C-Style declarations, are they here to stay?!! Walter?

Hasan Aljudy hasan.aljudy at gmail.com
Mon Apr 3 17:45:13 PDT 2006


Walter Bright wrote:
> Hasan Aljudy wrote:
> 
>> why is foo(y) allowed at the global scope? and why is it disallowed at 
>> local scope?!!
> 
> 
> It should be disallowed at global scope as well. I'll add it to the list 
> of bugs to be fixed.

ok, here's another corner case.

Should
foo(*bar)
be allowed as a declaration?
The C-Style declaration syntax allows it, but this makes the D Grammar 
*not* context free, because foo(*bar) can be a function call, depending 
on what foo and bar are.

     //I'm using dmd 0.146
     alias int foo;
     foo(*y); //ok
     int(*z); //ok
     static this()
     {
         y = null;
         z = null;
     }
     void main()
     {
         int(*w); //ok
         foo(*x); //error
         x = null;
         w = null;
     }

Also notice how there's no problem with "int" (because it's not an 
identifier) while there is a problem with foo, even though it's just an 
alias for int, and supposedly the semantic analyzer sees them as the 
same thing.

I'm not an expert on CFGs (context free grammars) but I think it's 
pretty complicated to design a grammar that allows
foo(*bar)[x];
as a declaration, but disallows
foo(*bar);
as a declaration.




More information about the Digitalmars-d mailing list