You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#include<iostream>
#include<cmath>intmain()
{
int x=1;
std::cin >> x;
int y=0;
if (x==1 || x==2)
{
y = 3;
} else
{
y = 4;
}
x = 2;
int z = 3;
if (x==1 || x==2)
{
z = 13;
} else
{
z = 14;
}
std::cout << z << std::endl;
return0;
}
By the end of the code, -O3 -g will yield optimized out for variable y
gdb-peda$ p y
$1 = <optimized out>
-O1 yields same results
Applying -O0 will show the value of y but in -O3 state, we can use volatile int y=0;
This yields:
gdb-peda$ p y
$1 = 0x4
when std::bad_cast exception
bt may not work. Need to stop throw
catch throw then run the execuble within gdb, to stay in the stack memory