Hi,

>>>(((char *)address + 3) & ~3)
>> I simply use this on each char* pointer? That's it?

There shouldn't be any need for aligning addresses manually if the code
is done properly using correct types, sizeof() & offsetof() and not
trying to cast pointers to something that needs larger alignment.
-Wcast-align gcc option warns about the last one, but it
can show some false positives.


Only instance when you need to do alignment manually instead of
letting the compiler do it automatically for you is if you want
to have the same data to be readable by programs running on
different architectures, or compiled with different compiler
or compiler options (affecting the sizes of things.

Otherwise one just needs to be careful.


So, what is done to this so that it breaks:
struct MyHeaderSummary
  {
     int16 foo;
     char bar;
     char text[SOMELEN];
  };
?

(If program saved stuff like this as a snapshot from memory,
it should obviously be able to be read it back to memory too.)


As to this:
  struct MyHeaderSummary
  {
     int16 foo;
     char bar;
     char string[MAXLEN]  __attribute__ ((aligned (4)));
  };

If the point of this is to align the "string" member as a pointer
would, 4 is not correct alignment for 64-bit architectures.


        - Eero

_______________________________________________
maemo-developers mailing list
maemo-developers@maemo.org
https://maemo.org/mailman/listinfo/maemo-developers

Reply via email to