Jonathan M Davis wrote:
> On Thursday 16 September 2010 23:50:16 Kagamin wrote:
>> BCS Wrote:
>>> The trick is that function pointers are best read from the inside out.
>> All C declarations are read from inside out, postfixes take precedence,
>> that's why you have to use braces to give pointer higher precedence. One
>> of the earlier books by Stroustroup gives a nice monster of arrays,
>> pointers and functions to master understanding of declarations.
>
> It's essentially the same principle that makes it so that the D declaration
>
> int[4][3] a;
>
> is an array with 3 rows and 4 columns rather than 4 rows and 3 columns like
> you'd expect.
>
> - Jonathan M Davis

I don't see it that D's declaration follows C's at least in array declarations:

int[4] is an array of 4 ints; like Simen, let's call it U.
Now U[3] is an array of 3 Us; i.e. 3 int[4]s

I read that from left to right, not inside out.

The equivalent C declaration has the opposite type:

    int a[4][3];

Now that is 4 arrays of 3 ints.

D wins big time here! :)

Two programs to test:

#include <stdio.h>
int main()
{
    int a[4][3];
    printf("%u\n", sizeof(a[0]));

    return 0;
}

Outputs 12.

import std.stdio;
void main()
{
    int[4][3] a;
    writeln(typeof(a[0]).sizeof);
}

Outputs 16.

Ali

Reply via email to