Any hints on how to prevent g++ from optimizing away my variables? Or at least I am assuming they are being optimized away, any hints/clues would be appreciated. For example:
int main(){
int n=0;
int a=3;
cout<<a;
return 0;
}
If this were my real program, then while debugging using insight I would not be able to see what n was holding by hovering over it or even putting a watch on it. While using the below compile command on the code above it works, it does not work in my actual app's script. Any guesses? Thanks in advance.
Declaring the variable volatile will prevent the compiler from storing the value in a register. I would not recommend using this as general practice; only for debug purposes, and then change it back to non-volatile when done debugging.
Thanks for the tip, I'll add it to the toolbag. Still though, there's got to be a way to force the compiler to retain all of the debugging info. Any other suggestions?
The compiler is free to optimize away any variables provided that:
1) They are not declared "volatile";
2) No code takes their address;
3) It is a POD-type that can be stored in a register.