C-Style declarations, are they here to stay?!! Walter?
    Hasan Aljudy 
    hasan.aljudy at gmail.com
       
    Fri Mar 31 18:16:29 PST 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.
I /think/ this comes from the C-Style declaration syntax ..
Decl:
         BasicType Declarators ;
Declarator:
         Identifier
         ( Declarator )
hence, int(x) has a parse tree which looks like:
       Decl
         |
    _____|_______
   |             |
BaiscType   Declarator
   |            |
  int       ____|_______
           |      |     |
           |      |     |
           ( Declarator )
                  |
                  |
              Identifier
                  |
                  |
                  x
The C-Style declaration syntax requires parenthesis around declarators, 
D-Style declaration syntax does not.
I think this is caught at the local scope because there's an ambiguity, is
# foo(x)
a function call or a declaration?
At the global scope there's no ambiguity, it must be a declaration.
However, inside function bodies, it could be a statement (function call 
or other things).
The code that disambiguates /assumes/ that foo(bar) declarations are not 
allowed, but the grammar allows it, and the docs don't indicate anywhere 
that foo(bar) is not a valid declaration.
Hence,
C-Style declarations cause ambiguities and trouble with the D 
declaration syntax.
Can they be gone now? :)
    
    
More information about the Digitalmars-d
mailing list