At 05:02 PM 12/19/2003, Peter Easton wrote:
Hi,

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"

You can't do this with the preprocessor since it doesn't have info on types. However, you can do this with the compiler by writing something like:


typedef int TEST_MYSTRUCT_SIZE[sizeof(MyStructType)] == 100];

If the expression inside the array bounds is false, it will evaluate to 0 which is an invalid array size. Otherwise, it will be 1, and you'll just be left with an unused typedef.

--
Ben Combee <[EMAIL PROTECTED]>
CodeWarrior for Palm OS technical lead
Palm OS programming help @ www.palmoswerks.com



-- For information on using the Palm Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to