Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
Announcements
The Intel sign-in experience has changed to support enhanced security controls. If you sign in, click here for more information.
7782 Discussions

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

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