volatile is not volatile enough
Richard Earnshaw
rearnsha@arm.com
Wed Jun 25 15:16:00 GMT 2003
> Hi,
>
> given a statement like
> int a[2];
> func2(func1(a), a[0], a[1]);
> where a is modified by func1, func2 receives wrong input on the stack. In
> detail, first a[1], then a[0] and then a is pushed onto the stack, then func1
> gets called and pops off its a -- which is modified after.
> Adding the keyword volatile doesnot help.
>
> I am using gcc 3.3 20030226 (prerelease) SuSE Linux 8.2.
>
> Here is a test script:
> #include <stdio.h>
> #define volatile
>
> volatile void *func1(volatile int[]);
> volatile void *func2(volatile void *, volatile int, volatile int);
>
> int main(void) {
> volatile int a[2] = {13, 101};
> volatile void *result;
>
> /* IMPACT
> The result on stdout should be x=14 y=102 not x=13 y=101.
> */
> func2(func1(a), a[0], a[1]);
>
Wrong. The result is unspecified. iso/iec 9899:1990 6.3.2.2 "The order
of evaluation of the function designator, the arguments and subexpressions
within the arguments is unspecified, but there is a sequence point before
the actual call."
R.
More information about the Gcc-bugs
mailing list