Why is align() on structures not allowed within unit-test code blocks?

GrahamC grahamc001uk at yahoo.co.uk
Sun Dec 4 06:01:15 PST 2011


Is there a good reason why align() applied to structure definitions is not allowed on the struct definition line within unit-test code blocks?

E.g.:

unittest {

     align(1) struct Foo {
        char	c;
 	      int		i;
    }

     void Bar() {
 	        Foo f;
     }

}

int main() {
     return 0;
}


fails to compile. The error message is:
    found 'align' instead of statement

The error message is the same for both DMD and GDC.

If you take the align(1) out it compiles OK.
If you move the structure definition out of the unit-test block but leave the align(1) in place it compiles OK.
If you put the align(1) on each member variable definition instead of the struct line it compiles OK.

If the structure type is only used within the unit-test code then I would think it ought to be possible to define it (including it's alignment attribute) within that unit-test code block.


More information about the Digitalmars-d-learn mailing list