www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - typo mapNode[6]* exits; instead of mapNode*[6] exits; but whats it

reply Codifies <nospam antispam.com> writes:
I'm not sure I understand what mapNode[6]* means! (the second 
version is what I wanted an array of 6 pointers)

oddly when assigning a null to one element of the array it cause 
an error as it was trying to do an array copy... so what's going 
on and what does that definition actually mean ?
Oct 10 2018
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Wednesday, 10 October 2018 at 13:24:42 UTC, Codifies wrote:
 I'm not sure I understand what mapNode[6]* means! (the second 
 version is what I wanted an array of 6 pointers)

 oddly when assigning a null to one element of the array it 
 cause an error as it was trying to do an array copy... so 
 what's going on and what does that definition actually mean ?
mapNode[6]* can be read right-to-left as 'a pointer to an array of 6 mapNodes'. For simplicity, let's use int instead of mapNode: unittest { int[6]* p; int[6] arr; p = &arr; (*p)[0] = 1; (*p)[1] = 2; (*p)[2] = 3; (*p)[3] = 4; (*p)[4] = 5; (*p)[5] = 6; assert(arr == [1,2,3,4,5,6]); } -- Simen
Oct 10 2018
parent Codifies <a b.com> writes:
On Wednesday, 10 October 2018 at 13:36:20 UTC, Simen Kjærås wrote:
 mapNode[6]* can be read right-to-left as 'a pointer to an array
right... hence the failed attempt at an array copy... now I understand...
Oct 10 2018