Re: Alignment - Structures and Other Things

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

 



On Wed, Apr 13, 2011 at 10:57 PM, Patrick Rutkowski <rutski89@xxxxxxxxx> wrote:
> Hmm, very interesting. Is it possible to determine what the
> memory alignment requirements are on a given implementation?
(I think: "... on a given architecture.")

Looking for portable ways, google found

http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2007-03/msg04634.html

don't know whether it is good or even correct.

> Or do you really have to go and manually look at the
> documentation for every system+arch you're releasing on, and
> manually keep track of alignment requirements?

Usually you should not need to keep track of alignment
requirments, I think. The code I meet often lost alignment issues
as soon as it was improved and written cleaner, which also
for me often solved byte order issues.

> I wrote a little test case which allocates a few dozen memory
> blocks with malloc() and then examines them to guess what the
> system's alignment seems to be, but obviously I don't want to
> use that as a final solution.

If you just need some "selector", what with something like
struct test_s { char c; long i;};
and checking if sizeof(struct test_s) is 8 (4 byte aligned) or 16
(8 byte aligned) or so?

oki,

Steffen


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux