Here's an idea
Posted Dec 9, 2007 23:27 UTC (Sun) by
pr1268 (subscriber, #24648)
Parent article:
Memory access and alignment
Here's an idea: Let's all go back to 8-bit architectures and we won't have this problem anymore. ;-)
Okay, that was my one dorky sarcastic comment for the day.
Seriously, I'm curious about what happens without programmer intervention: Recently I had to code for a struct that looked like this (a similar example is given in the packed attribute link in the article):
struct my_object {
uint32_t a;
char c;
char filler[3];
uint32_t* p1;
char** p2;
char** p3;
};
I'm using a 32-bit computer, so I know all pointers occupy 4 bytes. Deal is, the char filler[3] array was not going to be used in any shape or form in my program, but I instinctively put it there to pad the whole structure to a multiple of 4 bytes. Would GCC have done that for me automatically if I had not included the char filler[3]? Or, would GCC have re-arranged things had I moved the char filler[3] to the bottom of the structure (leaving char c where it is)? How does the -Os optimization affect this? Thanks!
(
Log in to post comments)