Good use of pragma pack

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

 



Hi,

I want to write a Linux driver that will be generic for ARM and Intel.
It will use some structures.  The driver will exchange struct with
hardware, so data must always have the same alignment.

On ARM920, I think that we can't have a pointer on an address that is
not multiple of 4. So what is the good pratice ?

Only use int in structure ?

To use pragma pack ?

To use bit field ?

Does it make a slower code ?

Do you have some pointers on that subject ?

In Linux source code, there are a lot of different use of pragma for
aix, macintosh...:

#pragma pack(1)
#pragma pack()

or

#ifdef macintosh
#pragma options align=power
#endif

or

#ifdef macintosh
#pragma options align=reset
#endif

or the most complicated :

#ifndef NO_PACK
#if defined (_DPT_AIX)
#pragma options align=packed
#else
#pragma pack(1)
#endif  /* aix */
#endif  // no unpack

...

#ifndef NO_UNPACK
#if defined (_DPT_AIX)
#pragma options align=reset
#elif defined (UNPACK_FOUR)
#pragma pack(4)
#else
#pragma pack()
#endif  /* aix */
#endif  // no unpack

Why not to define something like a global macro called PRAGMA or ...
instead of all this kind of hack ?

Thanks for your response.

-- 
Stephane List
http://slist.lilotux.net

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux