What's left for 1.0?
Walter Bright
newshound at digitalmars.com
Fri Nov 17 23:39:06 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 };
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.
>>> * 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));
D: auto imageData = new byte[5];
> A better comparison is C++, which has no problem with it's std library
> vector class:
>
> vector<int> imageData(5);
Yah got me there, C++ is one character shorter.
>>> * 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" };
So can D:
char *list[] = [ "eggs","bacon","milk","break" ];
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};
> }
True. I forgot it could (replacing "Point" with "struct Point").
More information about the Digitalmars-d
mailing list