Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.
I found, that is impossible to compile the following piece of code. The error is, that the Initializer element is not constant.
const code int x=(char*)&nv.b-(char*)&nv;
Logged In: YES
You are correct that this produces an error. But for cases
like this offsetof() is defined in stddef.h.
const int x = offsetof (struct test, b);
I'm not sure if we need to treat this as a bug or a feature
request. I tend towards the latter.
Philipp Klaus Krause
It seems to me that this is a feature request. From the C99 standard:
"An integer constant expression shall have integer type and shall only have operands that are integer constants, enumeration constants, character constants, sizeof expressions whose results are integer constants,
and ﬂoating constants that are the immediate operands of casts."