Peter Easton <[EMAIL PROTECTED]> wrote:
> I'm looking to receive some kind of compile-time notification if a structure
> size isn't what I'd expect it to be. Something like:
>
> #IF SIZEOF(MyStructType) != 100 DISPLAY "Oops, there's problem"
Sadly the sizeof operator is not available in the preprocessor (see also
question 10.13 of the C FAQ).
The usual trick is to try to cause a compilation error by doing something
like
char foo[sizeof (MyStructType) == 100];
except that that's not quite good enough ("char foo[0]" is a valid
declaration e.g. with GCC in the absence of -pedantic), so the following
is better:
char foo[(sizeof (MyStructType) == 100)? 1 : -1];
That was cribbed from the Poser source code -- Keith discovered that
"char foo[0]" had become valid at some stage and improved the macro he
was using for the thing you want to do. Look at COMPILE_TIME_ASSERT in
EmCommon.h for details.
John
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/support/forums/