P
pemo
If you were to compile/run the code below, and get the result '30', I'd be
very interested to know what compiler you're using - and its optimisation
settings [esp. if it supports the 'restrict' keyword]
#include <stdio.h>
int test(int * a, int * b)
{
*a = 5;
*b = 6;
return (*a) * (*b);
}
int main(void)
{
int x = 0;
int a = test(&x, &x);
printf("%d\n", a);
}
The 'hope' with the code was to find a case where the gcc optimiser doesn't
fetch *a and *b, but assumes their values to be 5 and 6. The gcc I'm using
produces 36 irrespective of what ever n's value is in -On switches.
I wanted to be able to compile some code with various optimisations - and
show that the code 'breaks' when a and b point to the same variable in main,
and then to introduce 'restrict' to show it get fixed. Would the above be a
reasonable candidate for showing such a thing?
very interested to know what compiler you're using - and its optimisation
settings [esp. if it supports the 'restrict' keyword]
#include <stdio.h>
int test(int * a, int * b)
{
*a = 5;
*b = 6;
return (*a) * (*b);
}
int main(void)
{
int x = 0;
int a = test(&x, &x);
printf("%d\n", a);
}
The 'hope' with the code was to find a case where the gcc optimiser doesn't
fetch *a and *b, but assumes their values to be 5 and 6. The gcc I'm using
produces 36 irrespective of what ever n's value is in -On switches.
I wanted to be able to compile some code with various optimisations - and
show that the code 'breaks' when a and b point to the same variable in main,
and then to introduce 'restrict' to show it get fixed. Would the above be a
reasonable candidate for showing such a thing?