grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Fix packing issue of machine_mmap_entry


From: Christian Franke
Subject: Re: [PATCH] Fix packing issue of machine_mmap_entry
Date: Tue, 23 Oct 2007 10:09:08 +0200

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







reply via email to

[Prev in Thread] Current Thread [Next in Thread]