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?
Customer Value Optimization (CVO) is a process to create a great customer journey and maximize the ROI for all marketing activities. It focuses on optimization throughout the customer lifecycle to improve brand and loyalty—and create customers for life.
To view the "optimized-out" value of a variable during debugging, you need to turn off gcccompiler optimization, either on a per-variable basis, or program-wide. If you are interested in a particular variable in gdb, you can delare the variable as "volatile" and recompile the code.
It means you compiled with e.g. gcc -O3 and the gcc optimiser found that some of your variables were redundant in some way that allowed them to be optimised away. In this particular case you appear to have three variables a, b, c with the same value and presumably they can all be aliassed to a single variable.
Code optimization is any method of code modification to improve code quality and efficiency. A program may be optimized so that it becomes a smaller size, consumes less memory, executes more rapidly, or performs fewer input/output operations.
On high optimization levels, the compiler can eliminate intermediate values, as you have seen here. There are a number of options:
-O0
is certain to work (but will be quite a lot slower), -O1
might work okay as well.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