Herb Sutter briefly discusses D during interview

Jonathan M Davis jmdavisProg at gmx.com
Wed Jun 8 09:55:43 PDT 2011


On 2011-06-08 09:33, Timon Gehr wrote:
> Jonathan M Davis wrote:
> > Sight correction (I was in too much of a hurry when I typed that). The
> > parsing is done left-to-right just like the lexing/scanning is (it has
> > to be). However, the processing of the AST is effectively done outward
> > from the variable name. That is, the semantic analysis of the type is
> > done outward from the variable name and thus left-to-right. So, as far
> > as the compiler getting any meaning out of the type and figuring out
> > what to do with it goes, it reads right-to-left, _not_ left-to-right.
> > And if you try and read it like a compiler does - e.g. pointer to
> > pointer to int, not int pointer pointer - then you'll end up reading it
> > right-to-left too.
> > 
> > - Jonathan M Davis
> 
> Seems like we are agreeing perfectly. As to pointer to pointer to int vs
> int pointer pointer, the only difference is:
> 
> pointer to pointer to int
> <=>
> pointer -> pointer -> int
> 
> int pointer pointer
> <=>
> int <- pointer <- pointer
> 
> Both describe the same AST. Therefore both describe the way the compiler
> handles it. I prefer int pointer pointer for the same reason the compiler
> prefers it.

Except that it _does_ matter. The compiler _must_ look at types in a 
particular way to decipher the correctly. For instance, it's why

int[10][3] a;

can't be indexed with a[9][2]. That's why

int[10][3] a;

and

int a[3][10] a;

are equivalent. It has a huge impact on understanding C-style function 
pointers. It is _not_ interchangeable. The compiler must read types in a 
specific way to decipher them correctly, and that's outward from the variable 
name, which generally means right-to-left.

- Jonathan M Davis


More information about the Digitalmars-d mailing list