I have the following code:
typedef void* EstimatedValue;
EstimatedValue myFunction()
{
int myVal = 16;
EstimatedValue value = &myVal ;
return value;
}
bool intLessOrEqual(EstimatedValue value1, EstimatedValue value2)
{
return *(int*)value1 <= *(int*)value2;
}
And this main function:
int x = 8;
EstimatedValue val = myFunction();
EstimatedValue x1 = &x;
intLessOrEqual(x1, val);
However, the value of the second argument (the one that is created in the function) is corrupt inside the intLessOrEqual
function (the value is -858993460).
If I try to access *(int*)val
inside the main
function it works ok. What could be the reason for this behavior?
What can be done in order to avoid this behavior