Cannot alias null

Ali Çehreli via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 12 15:54:20 PDT 2014


On 06/12/2014 03:38 PM, monarch_dodra wrote:

 > Yet you can alias variables...
 >
 > int i;
 > alias j = i;

Initially I forgot about the fact that symbols can be alias'ed as well. 
So that's fine.

 > So there's something special about "null".

The difference is that null is an expression. It is the same limitation 
as not being able to alias a literal.

     alias zero = 0;
     alias blah = null;

Those two declarations fail for the same reason:

   Error: basic type expected, not 0
   Error: semicolon expected to close alias declaration
   Error: basic type expected, not null
   Error: semicolon expected to close alias declaration

The pair of error messages are somewhat silly: The first one is 
misleading because as we know, it should say "basic type *or symbol* 
expected"; and the second one is bogus because there actually is a 
semicolon there: :p

Ali



More information about the Digitalmars-d-learn mailing list