Why does this work?

Jason House jason.james.house at gmail.com
Thu Feb 17 21:06:26 PST 2011


Vladimir Panteleev Wrote:

> int foo;
> enum bar = foo+2;
> 
> void main()
> {
> 	foo = 7;
> 	assert(bar == 9);
> }
> 
> -- 
> Best regards,
>   Vladimir                            mailto:vladimir at thecybershadow.net

I would have expected bar to equal 2 since foo would be default initialized to 2. I'm going to guess that the there's some kind of optimization that only assigns to foo once and isn't noticing that bar depends on it. You should probably post that in bugzilla.


More information about the Digitalmars-d mailing list