www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Mixing array prefix/postfix declaration

reply simendsjo <simen.endsjo pandavre.com> writes:
The following is illegal:
int a, *b; // multiple declarations must have the same type, not int and int*

C style functions is also deprecated.

C style array declarations is still supported (but frowned upon..?).

But why are C and D style array declarations supported on the same declaration?
Isn't this both confusing and unnecessary?

// D style
int[2][1] a;
static assert(is(typeof(a) == int[2][1]));

// C style
int b[1][2];
static assert(is(typeof(b) == int[2][1]));

// Mixed
int[4][3] c[1][2];
static assert(is(typeof(c) == int[4][3][2][1]));
Apr 03 2011
next sibling parent simendsjo <simen.endsjo pandavre.com> writes:
I just noticed that the documentation contradicts itself.
Array says:
"
Rationale: The postfix form matches the way arrays are declared in C
and C++, and supporting this form provides an easy migration path
for programmers used to it.
"

And Declarations says:
"
C-style array, function pointer and pointer to array declarations
are deprecated:
"

But when trying to use C style functions I get this error:
"
C-style function pointer and pointer to array syntax is deprecated.
 Use 'function' to declare function pointers
"

But the arrays doesn't give an error. So... Is C style array
declarations deprecated?
Apr 03 2011
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
simendsjo:

 C style array declarations is still supported (but frowned upon..?).

C style array declarations are still supported, and accepted if you are porting C/C++ code to D. Otherwise it's generally better to use D style array declarations.
 But why are C and D style array declarations supported on the same declaration?

I will add this to Bugzilla.
 Is C style array declarations deprecated?

They aren't deprecated (yet). Bye, bearophile
Apr 03 2011
parent reply simendsjo <simen.endsjo pandavre.com> writes:
On 03.04.2011 19:14, bearophile wrote:
 simendsjo:
 But why are C and D style array declarations supported on the same declaration?

I will add this to Bugzilla.

I doubt it's a bug. It's done in the documentation too.
Apr 03 2011
parent bearophile <bearophileHUGS lycos.com> writes:
simendsjo:

 I doubt it's a bug. It's done in the documentation too.

You are right, it's not a bug, I have added it as enhancement request. Bye, bearophile
Apr 03 2011