Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

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

OPoly
Beginner
324 Views

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
324 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 ?

0 Kudos
Om_S_Intel
Employee
324 Views
I have submitted a report to Intel Compiler development team and requested to issue the warning in this situation. Om
0 Kudos
Reply