I have a function of this form:
void authenticate()
{
int auth_flag;
char password[16];
...
}
When I debug the program I can see that the auth_flag variable is after the password variable in the stack (which seems normal).
Now when I change the order of variable declarations:
void authenticate()
{
char password[16];
int auth_flag;
...
}
I see that variable auth_flag is still allocated after the password variable in the stack.
What I'm looking for is any way to avoid/control that, whether with a compilation option or in-code compiler directives.
According to GCC documentation "Common Function Attributes":
no_reorder
Do not reorder functions or variables marked
no_reorder
against each other or top level assembler statements the executable. The actual order in the program will depend on the linker command line. Static variables marked like this are also not removed. This has a similar effect as the-fno-toplevel-reorder
option, but only applies to the marked symbols.
And in "Optimize Options":
-fno-toplevel-reorder
Do not reorder top-level functions, variables, and asm statements. Output them in the same order that they appear in the input file. When this option is used, unreferenced static variables are not removed. This option is intended to support existing code that relies on a particular ordering. For new code, it is better to use attributes when possible.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With