On 13/04/11 21:57, Patrick Rutkowski wrote: > > On Apr 13, 2011, at 3:26 PM, Andrew Bell wrote: > >> malloc() will return memory on a boundary suitable for any type. If >> some types must be, say, 8-byte aligned, malloc will return memory >> that is 8-byte aligned. This of course satisfies types that are >> 4-byte, 2-byte and non-aligned. >> >> Your example code will end up breaking on some systems. >> >> This has nothing to do with specifically with GCC. > > Hmm, very interesting. Is it possible to determine what the memory > alignment requirements are on a given implementation? Or at least > with GCC in specific? It can be either a compile time or a runtime > solution, either is good for my purposes. > > 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? I can't quite tell what you're asking. C is designed so that you, never have to know the alignment requirements: program in a straightforward way and you'll be fine. Is it that you don't know what the rules are for writing C? Or that you know the rules, but for some special reason you want to violate them in non-portable code? Andrew.