CodeWarrior Tools for StarCore Processors

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CodeWarrior Tools for StarCore Processors

4,493 Views
marc_paquette
Contributor V
To help you find solutions to problems that have already been solved, we have posted this thread. Each message in this thread contains an entire topic ported from a separate forum. The original message and all replies are in a single message.
Labels (1)
Tags (1)
0 Kudos
1 Reply

943 Views
marc_paquette
Contributor V

To help you find solutions to problems that have already been solved, we have posted this message. It contains an entire topic ported from a separate forum. The original message and all replies are in this single message.

 

ahunanyan
Posted: Mar 02, 2005 - 01:47 AM   
 
Hi all.
According to
“Metrowerks\CodeWarrior\Help\PDF\MW_Enterprise_C_Compiler_Manual.pdf”
 
struct s {char a; int; char b[2];} v;
 
sizeof(v) is 3, but I got the size of that structure is 4 and in general all structures have 4 bytes aligned size.
 
Other issue: all structures have at least 4 bytes alignment regardless of structure content. Even if structure has one char member only, it is aligned to 4 bytes again.
 
For example:
 
struct z {char a; };
z- aligned to 4.
 
I have searched the solution in compiler options but haven’t found anything.
How I can avoid this 4 byte alignment problem ? 
 
 
   
 
mw_pirrle
Posted: Mar 03, 2005 - 07:45 AM   
 
Dear Customer,
 
By default the Compiler uses this alignment.
Some documentation (key) are available in the release note folder (<install_path>Release_Notes\StarCore_Notes\Compiler_Notes)
Extract of the SCC_COBJ_ICODE_undocumented_features.txt file
 
-I- Controlling data layout rules
=================================
By default the compiler follows the rules defined in the ABI when it has
create the layout of a given C variable.
In some cases these layout rules can be problematic when migrating existing code or when willing to minimize data size. The two most strigent points are:
structure alignment rules: the ABI states that a structure should be aligned at least on 4 byte boundary. This rule may induce unneccessary padding space
enumerated type mapping: the ABI states that enum are strictly equivalent to plain int disregrading the actual content of the enum.
 
bit field layout: the ABI states that a bit field is always considered as being part of a plain int container meaning that the compiler has to pad from the last bitfield field till the next 4 byte aligned container
 
These three rules can now be changed through options.
 
-I.1- Changing minimum structure alignment:
-------------------------------------------
 
scc -Xcfe "--min_struct_align=Value" ....
 
Where Value is >= 0
 
The effect is assuming we have a structure S containing fields f1, .. fn
 
Alignment(S) = Max ( Value, Max on f1 .. fn (Alignment (fi))
 
It should be noticed that the ABI rule is equivalent to scc -Xcfe "--min_struct_align=0"
 
For example: pad.c
 
#include <stdio.h>
typedef struct {
short f1;
} T1;
typedef struct {
char f1;
struct {
char f21;
char f22;
} f2;
char f3;
} T2;
void main()
{
printf("Sizeof(T1) = %d\n", sizeof(T1));
printf("Sizeof(T2) = %d\n", sizeof(T2));
}
 
scc -O3 pad.c
Sizeof(T1) = 4
Sizeof(T2) = 12
 
scc -Xcfe "--min_struct_align=0" -O3 pad.c
Sizeof(T1) = 2
Sizeof(T2) = 4
 
The paths and files names are for the Starcore V2.6.

 
If you're using an older version all these information are available too in the same folder but may be under other file names.
 
Regards
Pascal Irrle
 
 
  
 
ahunanyan
Posted: Mar 04, 2005 - 04:52 AM   
 
Thank You.
 
With best regards
Armen

 
0 Kudos