What is this strange alias syntax?

Steven Schveighoffer schveiguy at yahoo.com
Mon May 23 03:50:42 PDT 2011


On Sun, 22 May 2011 11:20:15 -0400, Timon Gehr <timon.gehr at gmx.ch> wrote:

> Andrej Mitrovic wrote:
>> Should I file a bug report to kill this syntax?
>
> No. It is perfectly valid, see grammar:
> http://www.digitalmars.com/d/2.0/declaration.html
>
> What is strange about this syntax in particular?
>
> int i; //declares i of type "int"
> alias int i; //defines i as type "int"
>
> int func(int); //declares func of type "function that takes int and  
> returns int"
> alias int func(int); //defines func as type "function that takes int and  
> returns int"
>
> It is perfectly consistent with other uses of alias.

It is not perfectly consistent.  The function type syntax is useless,  
because you can only use it if you use the pointer modifier with it.  If  
you want to declare a function pointer, there are other (better) ways.

Yes, removing it would be a "special case" for the compiler, but it's  
syntax and usages are so bizzare, nobody would miss it.  it's akin to  
making:

if(x);

invalid.  Yes, it's valid syntax, but it's almost certainly not what the  
user wanted.  It's special cased for failure, to aid the developer in  
writing less buggy programs.  This would be a similar change, and I  
actually thought it was already in the compiler.

I'll throw it back at you, do you see a good use case for it?  And no,  
porting C code isn't a good use case.

-Steve


More information about the Digitalmars-d-learn mailing list