Community
cancel
Showing results for 
Search instead for 
Did you mean: 
OPoly
Beginner
65 Views

How should "x = a[x]++" be compiled ?

It seems I either have forgotten how C works, or ICC has a very basic (and thus very serious bug).
When compiling   x = a++;   ICC does not increment the array value, while GCC does (as it should).
I am using the latest ICC (14.0.2). This toy code shows this:

#include <stdio.h>
int main(void)
{
    int a[1] = {5}, i = 0;
    i = a++;
    printf("%d %d\n", i, a[0]);
    return 0;
}

0 Kudos
2 Replies
OPoly
Beginner
65 Views

Ok, I found that since there is a double memory reference, the ordering of "++" is undefined by the C standard.

But why does it not generate a warning at least ?

Om_S_Intel
Employee
65 Views

I have submitted a report to Intel Compiler development team and requested to issue the warning in this situation. Om
Reply