Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7646 Discussions

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

OPoly
Beginner
147 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
147 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
147 Views
I have submitted a report to Intel Compiler development team and requested to issue the warning in this situation. Om
Reply