How to enable the 'Pack Structure' option in GCC

How to enable the 'Pack Structure' option in GCC

Post by Khanh Phi Van Do » Tue, 01 Aug 1995 04:00:00



Hi,

Does anyone know the command line option for Packing Structures under
gcc?  For example, the following structure normally takes up 8 bytes
of storage because gcc by default try to allign each element of the
structure on a double word boundary:

struct {        // should only take up 5 bytes
  char  x;      // 1 byte
  int   y;      // 4 bytes

Quote:}

How do I turn this feature off?
Thanks for your help on this.

Khanh Doan

 
 
 

How to enable the 'Pack Structure' option in GCC

Post by Miquel van Smoorenbu » Thu, 03 Aug 1995 04:00:00




Quote:>Hi,

>Does anyone know the command line option for Packing Structures under
>gcc?  For example, the following structure normally takes up 8 bytes
>of storage because gcc by default try to allign each element of the
>structure on a double word boundary:

>struct {    // should only take up 5 bytes
>  char      x;      // 1 byte
>  int       y;      // 4 bytes
>}

>How do I turn this feature off?
>Thanks for your help on this.

>Khanh Doan

Try the following:

#ifdef __GCC__
#  define PACKED __attribute__((packed))
#else
#  define PACKED
#endif
struct structname {     // should only take up 5 bytes
  char  x PACKED;       // 1 byte
  int   y PACKED;       // 4 bytes

Quote:};

Now, if you want an array of this struct of which the individual members
are _also_ not aligned you'd also say:

struct structname a_struct[10] PACKED;  // Takes up 50 bytes.

Oh, I got this magic from a few hints in /usr/include/linux/sysv_fs.h :)

Hope this helps, Mike.
--
+ Miquel van Smoorenburg + Cistron Internet Services +  Living is a     |



 
 
 

1. How to enable 'fastboot' option in rc.sysinit

The subject says it all: How do I enable the 'fastboot' option found in
/etc/rc.d/rc.sysinit. I've checked the faqs and my usual q+a sites, but
can't seem to find anything.

(Yes, I know that turning this on is a bad idea, but I need to do it
anyway.)


Thanks
LR

2. IPC performance of recent kernels (ctxbench)

3. What's 'side effects' of Ksh built-ins?

4. bonehead question

5. gcc: unrecognised option '-qmagic'

6. Screen Lock don't work (CDE, NIS+)

7. '-i' option for 'cp' and 'mv'

8. Memory consumption script

9. Solaris C compiler structure packing option

10. Packing structures - GCC question

11. GNU GCC and packed structures?

12. Apache patch to allow 'Options None' when Options override disallowed

13. 'make' and 'gcc' don't work