Non-nullable references, again

Andrei Alexandrescu SeeWebsiteForEmail at
Wed Dec 31 23:17:13 PST 2008

Daniel Keep wrote:
> Michel Fortin wrote:
>> On 2008-12-31 21:50:53 -0500, Daniel Keep 
>> <daniel.keep.lists at> said:
>>> Disclaimer: I'm not an expert on compilers.  Plus, I just got up.  :P
>>> The key is that the parser has to know what "MyClass" means before it 
>>> can figure out what the "?" is for; that's why it's 
>>> context-dependant. D avoids this dependency between compilation 
>>> stages, because it complicates the compiler.  When the parser sees 
>>> "MyClass", it *doesn't know* that it's a type, so it can't 
>>> distinguish between a nullable type and an invalid ?: expression.
>> As far as I know, this can't be done with pointer declarations. Read 
>> this:
>>     a * b;
>> Is it a multiplication or a declaration of a pointer to type "a"? You 
>> don't know until you resolve the identifiers. It's the exact same 
>> situation for using "?" to denote nullable.
>>> At least, I think that's how it works; someone feel free to correct 
>>> me if it's not.  :P
>> I belived the same for some time too, then found the above rebutal.
> I don't think so; I believe that unary vs. binary operators are 
> unambiguous.  "a * b" is "a multiply b" because it's "(expr) * (expr)". 
>  It's pointer dereference when it's "* (expr)".
> I keep in mind is that "(expr) < (expr) >" is ambiguous, but "* (expr)" 
> isn't.
> Like I said, I'm not an expert, so take what I say with a grain of salt.
>   -- Daniel

It's about a pointer declaration, not a pointer dereference, a la "int * p;"

Happy New Year everyone!


More information about the Digitalmars-d mailing list