Bug 953 – Multiple C style declarations of same type cannot be in one statement

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2007-02-12T07:05:00Z
Last change time
2017-07-10T23:10:15Z
Keywords
bootcamp, diagnostic
Assigned to
nobody
Creator
matti.niemenmaa+dbugzilla
Blocks
10233

Comments

Comment #0 by matti.niemenmaa+dbugzilla — 2007-02-12T07:05:47Z
int foo[2], bar[2]; The above fails with the error message "multiple declarations must have the same type, not int[2] and int[2]" which makes no sense. int[2] is the same type as int[2].
Comment #1 by bugzilla — 2007-03-20T03:41:26Z
This is by design. The declaration should be: int[2] foo, bar; More than one C-style declaration in the same line is not allowed.
Comment #2 by matti.niemenmaa+dbugzilla — 2007-03-20T04:10:56Z
Then it's a problem with the error message, which should say that, instead of its current nonsense.
Comment #3 by witold.baryluk+d — 2009-08-10T05:10:34Z
Hi, i just tried in DMD 1.043 int a[8], c[8]; and given me this nonsensical error. I know this is redudant, but is there to allow C style declarations. I just switch many times from C to D, and sometimes forgot where am I. In declarations.html we read: "In a declaration declaring multiple symbols, all the declarations must be of the same type: int x,y; // x and y are ints int* x,y; // x and y are pointers to ints int x,*y; // error, multiple types int[] x,y; // x and y are arrays of ints int x[],y; // error, multiple types " I was all my life (actually life when i use D, so about 3 years) thinking this means, that: int[8] a,b,c; is equivalent of int a[8], b[8], c[8]; how about adding to spec example this entries: int[2] x,y; // x and y are static arrays of ints int x[2],y; // error, multiple types int x[2],y[2]; // error, multiple types int x[2],y[3]; // error, multiple types
Comment #4 by andrej.mitrovich — 2013-01-20T11:37:50Z
This affects both D1 and D2.
Comment #5 by andrej.mitrovich — 2013-01-20T11:45:33Z
This would be more simple to implement if we simply destroyed C-style array syntax. I don't know why we're waiting so long to get rid of them.
Comment #6 by andrej.mitrovich — 2013-01-20T11:46:05Z
(In reply to comment #5) > This would be more simple to implement if we simply destroyed C-style array > syntax. Read that as: C-style declarations, because it also affects pointers.
Comment #7 by bearophile_hugs — 2013-07-03T10:17:37Z
So this code has different meanings in C and D: void main() { int *a, b; } And to keep the D language simple this is disallowed: int a[8], c[8]; Then what is this issue asking for? In Issue 5807 I have suggested to disallow mixing C and D style of array in a single declaration: // array of 5 dynamic arrays of ints. int[][5] c; int[] c[5]; int c[5][]; Also because of some problems it causes with vector ops syntax: void main() { int[] a1 = [1, 2, 3]; int[] a2 = new int[3]; a2[] = a1[]; // OK int[3] a3[] = a2[]; // line 5, Error } Beside disallowing the mix of C and D syntaxes in a single declaration, another thing that may be good to do is to perpetually deprecate the C syntax (and do not turn it into an error).
Comment #8 by dlang-bugzilla — 2017-07-10T23:10:03Z
(In reply to Matti Niemenmaa from comment #0) > int foo[2], bar[2]; > > The above fails with the error message "multiple declarations must have the > same type, not int[2] and int[2]" which makes no sense. int[2] is the same > type as int[2]. Fixed by https://github.com/dlang/dmd/pull/4021. Now it prints: test.d(1): Deprecation: instead of C-style syntax, use D-style syntax 'int[2] foo' test.d(1): Deprecation: instead of C-style syntax, use D-style syntax 'int[2] bar'
Comment #9 by dlang-bugzilla — 2017-07-10T23:10:15Z
*** Issue 12196 has been marked as a duplicate of this issue. ***