Array declaration warning
Paul via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 2 09:34:28 PDT 2015
On Tuesday, 2 June 2015 at 16:22:58 UTC, Alex Parrill wrote:
> On Tuesday, 2 June 2015 at 16:17:23 UTC, Paul wrote:
>> This array of structures...
>>
>> CoOrd pathList[NumPaths][];
>>
>> generates a warning when compiled with DMD 32 bit -w flag, but
>> not 64 bit.
>
> This gives me a warning using rdmd on x64 XUbuntu.
>
>> If I correct the declaration to 'D style'
>>
>> CoOrd[NumPaths][] pathList;
>>
>> It compiles without warning but I cannot append items to the
>> array like this...
>>
>> pathList[n] ~= CoOrd(cX, cY);
>>
>> What am I doing wrong?
>
> `CoOrd[NumPaths]` is a fixed-length array type containing
> `NumPaths` elements. You can't append to it.
> `CoOrd[NumPaths][]` is a dynamic array of such arrays, but
> `pathList[n]` gets one of the fixed-length arrays from the
> dynamic array.
>
> Perhaps you mean `CoOrd[][NumPaths]`?
Thank you, i guess that will work although it doesn't fit with my
way of thinking about the problem, ie there are a fixed number of
paths of variable length, eg...
pathList[0] (43, 60), (44, 60) ... <- append items
pathList[1] (55, 801), (56, 802), (56, 803) .... <- append items
pathList[2] etc
In case it's of interest I was compiling on Mint 17 64bit and
Mint 17.1 32bit, both with latest DMD.
More information about the Digitalmars-d-learn
mailing list