Thread overview
Mixing array prefix/postfix declaration
Apr 03, 2011
simendsjo
Apr 03, 2011
simendsjo
Apr 03, 2011
bearophile
Apr 03, 2011
simendsjo
Apr 03, 2011
bearophile
April 03, 2011
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]));
April 03, 2011
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?
April 03, 2011
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
April 03, 2011
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.
April 03, 2011
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