Perica wrote:
Or, can i make the assumption that when compiling this code for such a platform, the data will receive the proper alignment etc. ?
In general, any variables allocated in your stack frame or at translation unit or global scope in C will have sufficient alignment for their natural use.
Any memory allocated with malloc() and friends will have alignment sufficient for the most restrictive type for the CPU (if your CPU requires some data to be aligned on an 8-byte boundary, then malloc() will return space aligned on an 8-byte boundary).
Any struct definitions that haven't been messed about with by somehting like GCC's __attribute__ ((packed)) notation will have all field offsets within them aligned appropriately to their type, assuming that the base of the struct is aligned as if it was returned from malloc().
In general, you aren't likely to run into too much trouble, since many systems merely suffer performance degredation from unaligned access rather than taking an exception. For most of the rest, you're only going to run into trouble when parsing structured data by hand.
Of course there are still platforms out there with weird and wonderful addressing setups such as only supporting 36-bit wide words, and only supporting word addressing, but you aren't likely to run into these in practice.
(For more weird and wonderful memory addressing semantics, there are systems out there which, when you read memory, checks to see if it has a 'forwarding pointer' which tells the system to go read a
different memory location for the real data.)
But, as I said, unless you're going to target something messed up like a 68000 (
not a 68020 or better, the original 68000), some of the PDPs, or Lisp Machine hardware, alignment isn't something to waste too much worry on.