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

Position of declarations

gib
New Contributor II
543 Views

Hi, I'm compiling with icl some code that has previously been compiled with gcc. I'm getting errors because icl doesn't like declarations appearing after executable statements in a function. I can fix these errors by moving the declarations to the top of the functions, but I'm wondering is there is a compiler option that would take care of it. The source files have '.c' extension, and I'd rather not change that.

Thanks

Gib

0 Kudos
10 Replies
Om_S_Intel
Employee
543 Views

As long as you follow C language syntax, icc should compile without issue. The icc works for me.

$ cat hello.c

//hello.c

#include

int main()

{

printf("Hello World...!!!\n");

int x, y, z;

x = 5;

y = 10;

z = x+y;

float fx;

fx = 3.0* x;

printf("x = %d, y = %d, z = %d, fx = %f\n", x, y, z, fx);

return 0;

}

$ icc hello.c

$ ./a.out

Hello World...!!!

x = 5, y = 10, z = 15, fx = 15.000000

$ icc -V

Intel C Intel 64 Compiler Professional for applications running on Intel 64, Version 11.1 Build 20100128 Package ID: l_cproc_p_11.1.066

Copyright (C) 1985-2010 Intel Corporation. All rights reserved.

$ uname -a

Linux dpd22 2.6.18-52.el5 #1 SMP Wed Sep 26 15:26:44 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

0 Kudos
Om_S_Intel
Employee
543 Views

It will help if you couldpost test case.

0 Kudos
Milind_Kulkarni__Int
New Contributor II
543 Views

The workaround is to use:-- /Qstd=c99 option in Windows* . In Linux*, this option is not required.

0 Kudos
gib
New Contributor II
543 Views
Your hello.c gives errors on Windows. It compiles as hello.cpp.
0 Kudos
gib
New Contributor II
543 Views
Thanks Milind. My Makefile had -std=c99, not quite the same thing. It works now.
0 Kudos
gib
New Contributor II
543 Views

I can use /Qstd=c99 when compiling with icl, but because of the makefile problems I've encountered (see my other thread) I am now trying to build this application using MS Visual Studio. I've tried adding the following to Configuration Properties > C/C++ > Command line > Additional options:

-Qstd:c99

/Qstd:c99

-Qstd=c99

/Qstd=c99

-std:c99

-std=c99

/Qc99

but none works.

Since the help docs say of Qstd that

IDE Equivalent

Windows: Language > Enable C++0x Support

I looked for such an option in the project properties, but didn't find it.

Is there a way to get the effect of /Qstd=c99 in MSVS?

0 Kudos
Milind_Kulkarni__Int
New Contributor II
543 Views

When using MSVS, it seems you forgot to change to Intel compiler. so its using cl compiler, for which /Qstd=c99 does not work. To change the compiler, right-click Project in the Solution Explorer Window, and > Parallel Composer> Use Intel C++. Then the option will work.

If you want to work with MS compiler, then go to Properties>C/C++>Advanced>Compile As , and set as C++ code (/TP) option, and it will work, for icl as welll as cl. Hope it works in your case too.

0 Kudos
gib
New Contributor II
543 Views

I was just about to say "Do you think I'm stupid?" then I checked and found that I am! I didn't even realize that I had MSVC installed - this is my first foray into C for a few years.

Thanks.

0 Kudos
Milind_Kulkarni__Int
New Contributor II
543 Views
:) yes, you need to integrate the Intel Compiler to MSVS , if you have not already done. And check whether you can switch to Intel compiler in Visual Studio.
0 Kudos
gib
New Contributor II
543 Views
Yes, it was a single button click to switch MSVS over to Intel C++. I'm still amazed that I hadn't noticed that the compilation was not using the Intel compiler.
0 Kudos
Reply