I am working on a computation software written in fortran but I developed a little extension in C. The software have to be higly portable and among other constraints it have to compile on both GCC suite and Intel compiler suite. I normally test on GCC and everything was going well until I tried to compile with the intel suite. I got an "expected an expression" error on a simple for loop. I created a minimal test case and it appear that icc refuse to compile the declaration of a variable inside the for loop header.
#include <stdio.h>
int main(int argc, char** argv){
for(int i = 0; i < 5; i++){
printf("%d\n", i);
}
return 0;
}
This give me the following on intel 13, 15, 16, 17 and 18 (but not 19)
$ icc test.c -o ./test
test.c(4): error: expected an expression
for(int i; i < 5; i++){
^
test.c(4): error: identifier "i" is undefined
for(int i; i < 5; i++){
^
compilation aborted for test.c (code 2)
I am not a C specialist but I seen this form of for thousand of times and GCC have never been problem. Is this a GNU extension recently adopted by Intel ?