Here is the sample code:
#include <iostream>
#include <stdlib.h>
#include <cstdio>
int add(int x, int y){
return x + y;
}
int main(){
int x = 10;
int y = 10;
if(add(x, y) == 20){
printf("Here I am\n");
}
return 0;
}
I make a comparison between constant value 20 and the returned value of add()(without saving the returned value in a local variable). I was wondering is it safe to do that in c++?
My argument is that if we don't store the returned value back in the stack frame of main(), the returned value literally doesn't exist in the stack and it is only stored in the register like %eax, what if the value stored in %eax is edited before the comparison is made, then the program would probably go wrong.
