Properties no longer work?

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Jul 29 15:11:38 PDT 2006


"Bruno Medeiros" <brunodomedeirosATgmail at SPAM.com> wrote in message 
news:eafnr8$e4c$1 at digitaldaemon.com...

> Nope, I think it's there since K&R ANSI C, although I don't have the book 
> here with me to confirm.

Hm.

> "char x[];" is not valid C. "char x[]" is only valid when there is an 
> array initializer "char x[] = {...};", or as a function parameter type, 
> but in this latter case it is not an array, it is a char pointer (char*).

Oh that's right; in C[++], arrays and pointers _are_ separate types, it's 
just that when you pass an array into a function, the type info is lost and 
it just becomes a pointer.  That's why:

char x[] = "hello";
printf("%d", sizeof(x));

Prints 6 (length of string + null char), but

void fork(char x[]) // old-fashioned, same as "char* x"
{
    printf("%d", sizeof(x));
}

..
char x[] = "hello";
fork(x);

prints 4 (the size of a char*).

This is why I like D.  Arrays are actually first-class types. 





More information about the Digitalmars-d-learn mailing list