www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Removing the "int foo[];" syntax

reply "Brian Schott" <briancschott gmail.com> writes:
It complicates the grammar and doesn't fit with D's style of 
declaraing variables. (type then identifier) I realize that it 
was left in to make C programmers happy, but it doesn't even work 
like it does in C:

int a[10];
int b[10], b[10];
int[10] c, d;
int e[string];
int f[string], g[string];

test.d(2): Error: multiple declarations must have the same type, 
not int[10] and int[10]
test.d(5): Error: multiple declarations must have the same type, 
not int[string] and int[string]
Apr 30 2013
next sibling parent Jacob Carlborg <doob me.com> writes:
On 2013-05-01 00:36, Brian Schott wrote:
 It complicates the grammar and doesn't fit with D's style of declaraing
 variables. (type then identifier) I realize that it was left in to make
 C programmers happy, but it doesn't even work like it does in C:

 int a[10];
 int b[10], b[10];
 int[10] c, d;
 int e[string];
 int f[string], g[string];

 test.d(2): Error: multiple declarations must have the same type, not
 int[10] and int[10]
 test.d(5): Error: multiple declarations must have the same type, not
 int[string] and int[string]

I would say no if it was removed. -- /Jacob Carlborg
May 01 2013
prev sibling next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Brian Schott:

 It complicates the grammar and doesn't fit with D's style of 
 declaraing variables. (type then identifier)

I suggested something more moderate: to just disallow mixing C and D syntax in the same declaration: http://d.puremagic.com/issues/show_bug.cgi?id=5807
 I realize that it was left in to make C programmers happy,

For that I suggested a -cstyle switch, to be used only temporarily to port C code to D: http://d.puremagic.com/issues/show_bug.cgi?id=4580 Bye, bearophile
May 02 2013
prev sibling next sibling parent "Dicebot" <m.strashun gmail.com> writes:
On Tuesday, 30 April 2013 at 22:36:44 UTC, Brian Schott wrote:
 I realize that it was left in to make C programmers happy

I remember being mentioned by someone that it is more about simplifying porting of C headers to D than actually making C programmers happy.
May 02 2013
prev sibling next sibling parent "Dicebot" <m.strashun gmail.com> writes:
On Tuesday, 30 April 2013 at 22:36:44 UTC, Brian Schott wrote:
 I realize that it was left in to make C programmers happy

I remember being mentioned by someone that it is more about simplifying porting of C headers to D than actually making C programmers happy.
May 02 2013
prev sibling next sibling parent "deadalnix" <deadalnix gmail.com> writes:
On Thursday, 2 May 2013 at 08:18:48 UTC, Dicebot wrote:
 On Tuesday, 30 April 2013 at 22:36:44 UTC, Brian Schott wrote:
 I realize that it was left in to make C programmers happy

I remember being mentioned by someone that it is more about simplifying porting of C headers to D than actually making C programmers happy.

Array are value type in D so I'm not sure this really helps.
May 02 2013
prev sibling parent Jonathan M Davis <jmdavisProg gmx.com> writes:
On Wednesday, May 01, 2013 00:36:43 Brian Schott wrote:
 It complicates the grammar and doesn't fit with D's style of
 declaraing variables. (type then identifier) I realize that it
 was left in to make C programmers happy, but it doesn't even work
 like it does in C:
 
 int a[10];
 int b[10], b[10];
 int[10] c, d;
 int e[string];
 int f[string], g[string];
 
 test.d(2): Error: multiple declarations must have the same type,
 not int[10] and int[10]
 test.d(5): Error: multiple declarations must have the same type,
 not int[string] and int[string]

I think that deprecating the C-style syntax has been considered in the past, but I don't know what Andrei or Walter's stance on it is. I don't think that it adds much value though beyond making it slightly easier to port code from C to D, and I'm all for removing it. Most D programmers are probably using the D syntax anyway. - Jonathan M Davis
May 04 2013