What's left for 1.0?
Sean Kelly
sean at f4.ca
Sat Nov 18 08:25:38 PST 2006
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 };
>
>>> * No way to initialize a dynamic array with a known length
>>> byte[] imageData; imageData.length = 5; // two steps - meh
>
> C has no problem with this (using malloc, its own concept of "dynamic
> arrays"):
>
> byte* imageData = (byte*)malloc(5*sizeof(byte));
>
> A better comparison is C++, which has no problem with it's std library
> vector class:
>
> vector<int> imageData(5);
>
>
>>> * No way to initialize array of strings
>>> char[][] list = ["eggs","bacon","milk","break"]; //uh uh
>
> C can do this:
>
> char *list[] = { "eggs","bacon","milk","break" };
>
>>> * No way to initialize non-static struct
>>> Point p = { x:1.0, y:2.0 }; // nope...not static
>
> C has no problem with that either:
>
> struct Point { float x, y; };
> void foo() {
> Point p = {1.0,2.0};
> }
>
> (and C99 can do it with the x: y: syntax too, I think)
>
>>>
>>> * No way to initialize associative array
>>> char[int] strTable = {"hello":5, "hi":2, "greetings":9}; // no way
>
> Well you got me there. C can't do that.
I think C++ 0x *might* be able to do this. They've added initializer
lists for vectors, but I can't remember offhand if they will work for
maps as well.
Sean
More information about the Digitalmars-d
mailing list