Robert Millan wrote:
> ...
> > +/* Compile time assert to check packing */
> > +typedef char ASSERT_sizeof_grub_machine_mmap_entry[
> > +  sizeof (struct grub_machine_mmap_entry) == 4+8+8+4 ? 1 : -1];
> 
> Nice, I didn't know you could do compile time assertion in C.  But is
> it really necessary to check for gcc bugs?  That
> __attribute__((packed)) can only have the expected effect, right? 
> Besides, in this case maybe it'd be better to use autoconf.
> 

The check is not really necessary here, as the struct is simple, the
module is i386-pc only, and the project is gcc-only (e.g. due to nested
functions). I've added it during debugging of the Cygwin release, feel
free to remove it.

The compile time assert trick comes in handy for larger structs with
packing requirements, e.g.:
http://smartmontools.cvs.sourceforge.net/smartmontools/sm5/atacmds.h?r1=1.75&r2=1.76
(In this project, we got at least one gcc variant not supporting
__attribute__((packed)))

Another example: The code requires some size of a simple type:
  typedef char ASSERT_off_t_is_64bit[sizeof(off_t) == 8 ? 1 : -1];

Christian





_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to