I am using gdb to debug a C++ program.
I have this code:
int x = floor(sqrt(3));
and I want to view the value of x. However, gdb claims that x is “< optimized_out >”. How do I view the value of x? Should I change my compiler flags?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
On high optimization levels, the compiler can eliminate intermediate values, as you have seen here. There are a number of options:
-O0is certain to work (but will be quite a lot slower),-O1might work okay as well.