Herb Sutter briefly discusses D during interview
Jonathan M Davis
jmdavisProg at gmx.com
Wed Jun 8 08:57:16 PDT 2011
On 2011-06-08 08:38, Timon Gehr wrote:
> Jonathan M Davis wrote:
> > ...
> > No, people don't normally look at declarations such as
> >
> > int* a;
> >
> > as being right to left. But from the compiler's perspective, they are.
> > The
> >
> > compiler doesn't look at the type of a as being an int pointer. It looks
> > at it as being a pointer to an int. The * comes first and then the int.
> > [snip.]
>
> It is more convenient for the compiler to read the declaration left to
> right to construct the type. (just like for people)
I'm sorry, but no. Yes, the compiler lexes/scans the code left-to-right, but
in terms of how the type gets deciphered when parsing and using the resulting
abstract syntax tree, the compiler is effectively processing the type outward
from the variable, which almost always means right-to-left. The compiler has
no concept of stuff like int pointer or int pointer pointer. It knows about
pointer to int and pointer to pointer to int. And when you start looking at it
that way, it's clearly right-to-left. The compiler is _not_ looking at it the
way that a human normally does.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list