syntax question on "invariant" keyword
Michael Kiermaier
michael.kiermaier at gmx.net
Tue Jul 3 15:00:46 PDT 2007
I tried an example from
http://www.digitalmars.com/d/final-const-invariant.html:
*** begin Test.d ***
import std.stdio;
struct S
{
int x;
invariant int y;
}
void main() {
writefln(S.sizeof); // prints 4, not 8
}
*** end Test.d ***
Compilation gives the error message
Test.d(5): statement expected to be { }, not int
So I changed the line
invariant int y;
into
invariant {int y;}
and now the compilation works.
Why do I need the curly braces here?
And why does the example not work? Was there a change to the syntax rules of "invariant"?
Tanks in advance,
~michael
More information about the Digitalmars-d-learn
mailing list