Nitpicking the D grammar

Stewart Gordon smjg_1998 at yahoo.com
Sat Sep 8 14:50:34 PDT 2007


"Jascha Wetzel" <"[firstname]"@mainia.de> wrote in message 
news:fbrk6q$1cv5$1 at digitalmars.com...
<snip>
> Disallowing expressions without an effect is nice, but wouldn't a warning 
> suffice? After all the compiler can't find all expressions that have no 
> effect. Besides, adding for example two integers and not saving the result 
> (which is classified as a no-effect-expression) still has the effect of 
> changing the eflags register, which may be read in an asm block. So it's 
> questionable what "no effect" actually means.

Not if the compiler optimises it away.  As such, the contents of any 
register after such a statement would be undefined, so you can't really do 
anything with it.

> Wouldn't it be more appropriate here to change the specs to
> "Expressions that can be interpreted as a declaration, like (a*b), are 
> illegal in expression statements. If such an expression is needed, casting 
> it to void will make it legal."
> (http://www.digitalmars.com/d/statement.html#ExpressionStatement)

Such a statement in the spec would be null, because it isn't even parsed as 
an ExpressionStatement.

What the spec needs to do is properly document the disambiguation rules.

Stewart. 




More information about the Digitalmars-d mailing list