G
gamja
Hi all.
This is my first post on this group. Nice to meet you, cool guys~!
I'm on system programming on various embedded systems and understand
very well the byte alignment issues. When I write C code, especially
design a structure, I pay attention to the order and size of member
variables. Because, my boss always says that all variables should be
aligned by 4byte boundary, if not a data abort will be occurred on a
specific machine such like ARM.
However, I've never seen such situation. Because, my compiler
automatically aligns the boundary and gives padding properly between
each variable in the structure, if needed. Of course, pack option of
the compiler may change its behavior and this assumption may be break
easily. So, I agree with my boss.
The problem I want to ask is that he wants me to align all local
variables even in a function. For example, see the following code.
Case #1 - THIS IS NOT ALLOWED!!
int foo1()
{
char a;
int b;
short c;
...
}
Case #2 - THIS IS OK. GOOD.
int foo2()
{
char a;
char dummy[3];
int b;
short c;
...
}
I think this is bothersome and even ridiculous.
How do you think about?
Is the case #1 can make a data abort or bus error?
This is my first post on this group. Nice to meet you, cool guys~!
I'm on system programming on various embedded systems and understand
very well the byte alignment issues. When I write C code, especially
design a structure, I pay attention to the order and size of member
variables. Because, my boss always says that all variables should be
aligned by 4byte boundary, if not a data abort will be occurred on a
specific machine such like ARM.
However, I've never seen such situation. Because, my compiler
automatically aligns the boundary and gives padding properly between
each variable in the structure, if needed. Of course, pack option of
the compiler may change its behavior and this assumption may be break
easily. So, I agree with my boss.
The problem I want to ask is that he wants me to align all local
variables even in a function. For example, see the following code.
Case #1 - THIS IS NOT ALLOWED!!
int foo1()
{
char a;
int b;
short c;
...
}
Case #2 - THIS IS OK. GOOD.
int foo2()
{
char a;
char dummy[3];
int b;
short c;
...
}
I think this is bothersome and even ridiculous.
How do you think about?
Is the case #1 can make a data abort or bus error?