|
Technical Support Support Resources Product Information | GCC: ALIGNMENT PROBLEM WITH VARIABLES WITH GNU
Information in this article applies to: - GNU C Compiler for ARM Version 3.22
QUESTIONI have declared just a few variables in my application, but the data space seems to be quickly used up. When I define the following variables, it appears that there are big gaps in the memory layout:
int ival;
short sval;
long lval;
What is the reason for that? ANSWERThe GNU compiler has an alignment problem with uninitialized data. There are two possible work-arounds: - You may use variable initialization which avoids such gaps. For example:
int ival = 0;
short sval = 0;
long lval = 0;
An alternative is the GNU compiler directive -fno-common (enter under Options - CC - Misc Contorls: -fno-common). Using -fno-common, variables are placed into the .bbs section where alignment problems do not exist. However you may get side effects with libraries, since the library files must be translated consistently. To prevent the linker error Not enough room for program headers, try linking with -N, you need to add under Options - Linker - Misc Controls: -N.
SEE ALSOLast Reviewed: Monday, July 10, 2006
|
|