On  3/04, John Polstra wrote:

| I doubt if it's possible to implement that at compile time.  Remember,
| the preprocessor doesn't understand "sizeof".  It doesn't recognize
| keywords in expressions at all.

Then don't use the preprocessor alone and use both the preprocessor and
the compiler. I suppose something like this will work:

   struct foobar {
      ...;
   }

   #ifdef CHECK_STRUCT_SIZE
   #define MAX_FOOBAR_SIZE 8
   static char dummy_foobar [MAX_FOOBAR_SIZE-sizeof(struct foobar)];
   #undef MAX_FOOBAR_SIZE
   #endif

If sizeof(struct foobar) is more than MAX_FOOBAR_SIZE, then the compiler
will try to create an array with a negative size, which will not compile.
Embed this in a macro and you're done:

   #ifdef CHECK_STRUCT_SIZE
   #define CSS(S,T,U) static char dummy_##T [U-sizeof(S)];
   #else
   #define CSS(S,T,U)
   #endif

Then use:

   CSS(struct foobar,foobar,8)

 Sam



To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message

Reply via email to