Leveling C in the absence of power 2

There is a directive in gcc called .align that allows me to align objects at borders, which should be the power of two. However, on my Intel Core Duo machine, I want to align some code (not data) with addresses that are not the authority of the two. Is there an easy way to do this?

Because, obviously, .align 3 gives me an error: Error: alignment cannot be two.

+4
source share
2 answers

Power up two, and then overlay the appropriate number of assembler NOPs in front of the code you want to bias. (I assume that you know how to do inline assembler in gcc here, a comment if you do not.)

+3
source

Assuming you are using GCC, you can use packed structures and manual padding:

 struct very_slow_t { int a; char padding; int b; /* b is now padded to byte 5 */ } __attribute__((__packed__)); 

But why might you want to do this? I mean, this will make your program much slower.

0
source

All Articles