C-Style declarations, are they here to stay?!! Walter?

Hasan Aljudy hasan.aljudy at gmail.com
Fri Mar 31 14:43:10 PST 2006


<< I don't know if this has been discussed before, but I don't remember 
seeing any discussion about it. If it has been, please direct me to one 
of the old threads that discussed it. >>

I noticed that D supports the klumsy C-Style declarations, like

int (*x[5])[3];	   // x is an array of 5 pointers to arrays of 3 ints

I hate them!
To be honest, I never understood them; never tried to. This example is 
taken from the docs, and I really don't understand how does it make x an 
array of 5 pointers to arrays of 3 ints!!

D has nicer syntax,
int[3]*[5] x;	// x is an array of 5 pointers to arrays of 3 ints

I can't say I understand how it works, but when I read the description, 
is makes a lot of sense. It reads right to left:
[5]    array of size 5
*      pointer(s)
[3]    array of size 3
int    int(s)

array of 5 pointers to array of 3 ints!

The only reason I don't understand it right away is because I don't like 
nested complex declarations like this anyway, so I never tried to learn 
how to declare them. However, the D syntax makes alot of sense.

Consider for example this C-Style declaration:
int (*x)(char);

VS this D-Style declaration:
int function(char) x;

Why does D support int (*x)(char); anyway?!

Since D has a more intelligent way of declaring the same things, the 
C-Style syntax is unnecessarily redundant IMHO.

My understanding is that it's supported to attract the C/C++ people and 
get them familiarized with D quickly.

But, does this mean that C-Style declarations are gonna stay with D forever?

I personally would like to see them gone. but that's not for me to decide.

I mean, isn't the C-Style declaration syntax considered to be a design 
flaw in the original C? If so, does D really need to carry it out in 
order to attract C/C++ people?
That seems to be (to me) totally against the philosophy of D.

So Walter, I would like to please hear your opinion/decision about 
C-Style declarations; are they here to stay? or will they be deprecated 
at some point?














More information about the Digitalmars-d mailing list