What's left for 1.0?
Johan Granberg
lijat.meREM at OVE.gmail.com
Sat Nov 18 14:17:08 PST 2006
Bill Baxter wrote:
> Walter Bright wrote:
>> Bill Baxter wrote:
>>> Walter Bright wrote:
>>> > C can't do any of those things.
>>>
>>> Sure it can.
>>>
>>>>> * No way to initialize a static array without counting elements
>>>>> static byte[???] imageData = [...]; // i hope you like counting!
>>>
>>> C has no problem with this. I do it all the time:
>>>
>>> static const unsigned char[] = { 1,2,3,4,5,6,7, 255 };
>>
>> True, but that's only because C doesn't have dynamic arrays. In D,
>>
>> const char[] c = [ 1,2,3,4,5,6,7, 255 ];
>>
>> works fine, though it's a dynamic array.
>
> Yep it's great that D has built-in dynamic arrays, but the point is that
> the syntax for dynamic arrays is getting in the way of static arrays,
> making something that's simple in C become hard in D. If you want a
> static array you have no choice right now but to count up the elements,
> or deliberately use the wrong length to trigger compiler errors that
> will tell you the right length.
>
> If D has some other convenient and portable way to embed data like icons
> and images into one's exe, then I'd be interested in hearing about it,
> but for right now it seems to me like working with static data is a pain
> in D.
>
> Anyway, this one thing has actually been the biggest annoyance I've run
> across in trying to port C++ code to D. Most things become easier, but
> this one thing is harder in D.
>
I thought this would work but apparently it does not (what is the type of an
array literal?)
//begin code
static foo=[cast(ubyte)1,2,3,4,5];
void main()
{
printf("%d\n",foo.sizeof);
}
//end code
I get this error
johan at Dragon:~$ dmd test.d
test.d(4): Error: cannot infer type from initializer
which feels strange as i thought array literals defaulted to fixed size
arrays.
More information about the Digitalmars-d
mailing list