Does gcc has compile option for bytes alignment?

A

Allen

I know how to specify bytes alignment for a struct, i.e. using
__attribute__((aligned(4))).
But it is unconvenient because it must modify all struct, union and
class declaration.
Is there a compile option for gcc to define global bytes alignment?

For example, something looks like
#gcc -faligned4 -o test test.cpp

Thank you.
Allen
 
L

Lionel B

I know how to specify bytes alignment for a struct, i.e. using
__attribute__((aligned(4))).
But it is unconvenient because it must modify all struct, union and
class declaration.
Is there a compile option for gcc to define global bytes alignment?

For example, something looks like
#gcc -faligned4 -o test test.cpp

This ng does not deal with compiler-specific issues; you're more likely to
get help in a gcc forum such as gnu.gcc.help or gnu.g++.help

Thanks,
 
A

Allen

How did you check that?

union Test
{
char c;
int i;
float f;
};

I print sizeof(Test), when using -fpack-struct=8 and #pragma pack(8)
it outputs 4, while using __attribute__((aligned(8))) it outputs 8,
i.e. as same as set value.

Allen
 
M

Maxim Yegorushkin

union Test
{
char c;
int i;
float f;

};

I print sizeof(Test), when using -fpack-struct=8 and #pragma pack(8)
it outputs 4, while using __attribute__((aligned(8))) it outputs 8,
i.e. as same as set value.

The description says "... a set of #pragma directives which change the
maximum alignment of members of structures..." It is probably not what
you want.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top