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

ICC and C++ style comments

eliosh
Beginner
819 Views
Hello,

I am struggling with ICC that reports an error regarding stdlib.h
There is a couple of places where C++ style comments appear in this header.
Surprisingly, ICC refused to accept it. Here is the error I get:

/usr/include/stdlib.h(520): error: expected a declaration
// XXX There should be a macro to signal with C++ revision is used.


Looking at the file we see


#ifdef __USE_GNU
// XXX There should be a macro to signal with C++ revision is used.
// XXX This function is in the C++1x revision.
/* Register a function to be called when `quick_exit' is called. */
# ifdef __cplusplus
extern "C++" int at_quick_exit (void (*__func) (void))
__THROW __asm ("at_quick_exit") __nonnull ((1));
# else
extern int at_quick_exit (void (*__func) (void)) __THROW __nonnull ((1));
# endif



Isn't it a standard (now) / well accepted extension (before) ? Is it a bug in ICC?


Thank you.
0 Kudos
12 Replies
TimP
Honored Contributor III
819 Views
Technically, misinterpretation of // comments would be a bug if it happened with -std=c99 set in the command line or icc.cfg. Even without that, you would be entitled to file a bug report on premier.intel.com if you can submit a (preferably small) example where icc doesn't work like the gcc which is active, if it is one of those which is accepted as supported by icc at install time. At least you could expect a determination on where the reponsibility for divergence might lie.
0 Kudos
eliosh
Beginner
819 Views
Dear Tim,

Than you for your reply. Could you please report this error to the developers.
The testcase is very simple, please see the code below

[cpp]#include 

int
main (void) {
  return 0;
}
[/cpp]

When I compile the file with
icc -ansi dummy.c

I get no errors (which is probably wrong! but this is consistent with gcc)

When I compile it with
icc -ansi -D_GNU_SOURCE dummy.c

I get the aforementioned error (in contrast with gcc which detects no errors)

/usr/include/stdlib.h(520): error: expected a declaration
// XXX There should be a macro to signal with C++ revision is used.
^

/usr/include/stdlib.h(546): error: expected a declaration
// XXX There should be a macro to signal with C++ revision is used.
^

The file stdlib.h comes form the libc6-dev package (version 2.11.1-0ubuntu7.1) on Ubuntu 10.4.

I assume that -ansi flag should produce an error in this case, however, it is the combination -ansi -D_GNU_SOURSE that triggers icc.

P.S.
I am using ICC v. 11.1.072:

icc -V
Intel C Intel 64 Compiler Professional for applications running on Intel 64, Version 11.1 Build 20100414 Package ID: l_cproc_p_11.1.072
Copyright (C) 1985-2010 Intel Corporation. All rights reserved.
FOR NON-COMMERCIAL USE ONLY



0 Kudos
mecej4
Honored Contributor III
819 Views
I cannot reproduce the bug on my Suse 11.1 system with l_cproc_p_11.1.069 installed. There are no lines in stdlib.h that match the error-causing lines:

~/LANG> grep -i '// *XXX' /usr/include/stdlib.h
~/LANG>

Could it be that the bug is specific to Ubuntu?
0 Kudos
TimP
Honored Contributor III
819 Views
icc -ansi doesn't mean a standards check. Years ago, the option -ansi-alias (equivalent to gcc -fstrict-aliasing) was spelled that way, creating confusion. I don't think icc has given it a new meaning.
Could you explain what you are trying to achieve with GNU_SOURCE ? The option doesn't seem to be well documented, but (as far as I can tell) is intended to be set to support compilation of specific non-portable code intended for gcc only.
0 Kudos
eliosh
Beginner
819 Views
Tim,

The flags are set by MATLAB's mex complier (a shell script that creates a shared library from your sources). I am not sure they are vital. To resolve the issue with C++ comments I simply removed that '-ansi' flag from this script.

Thank you.
0 Kudos
Om_S_Intel
Employee
819 Views

I can compile the test case without any issue with icc.

$ icc tstcase.c

$ ./a.out

$ icc -V

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

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

$ uname -a

Linux maya11 2.6.29.4-167.fc11.x86_64 #1 SMP Wed May 27 17:27:08 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux

0 Kudos
jidnya
Beginner
819 Views
Om, I am using ICC 12.0 on a windows machine. I am getting compiler errors for C++ style comments as well when I compile using icc. Is there a compiler option to allow C++ style comments (e.g. //comments instead of /*comments*/).

Thanks,
Jidnya
0 Kudos
TimP
Honored Contributor III
819 Views
If ICL rejects comments which are accepted (in C mode) by MSVC, or C99 comments under /Qstd=c99, it looks like a bug, but it would be useful to have an example to reproduce it.
0 Kudos
SergeyKostrov
Valued Contributor II
819 Views
I can compile the test case without any issue with icc.
...


Hi,

Did you check the 'stdlib.h' header file forlines like these?

...
// XXX There should be a macro to signal with C++ revision is used.
// XXX This function is in the C++1x revision.
/* Register a function to be called when `quick_exit' is called. */
...

If you don't havecould add these three linesandcompile again? The compilation error looks like a bug in the compiler...

Best regards,
Sergey

0 Kudos
Om_S_Intel
Employee
819 Views

I am unable to reproduce the issue. I am using VS2010.

c:\>type tstcase.c

// tstcase.c

#include

// XXX There should be a macro to signal with C++ revision is used.

// XXX This function is in the C++1x revision.

/* Register a function to be called when `quick_exit' is called. */

int

main(void) {

return 0;

}

c:\>icl tstcase.c

Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.1.258 Build 20111011

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

tstcase.c

Microsoft Incremental Linker Version 10.00.40219.01

Copyright (C) Microsoft Corporation. All rights reserved.

-out:tstcase.exe

tstcase.obj

Did I miss something?

0 Kudos
jidnya
Beginner
819 Views
My bad. I am using Intel compiler which comes with Wind River's Workbench. By default -ansi compiler option is provided for C compiler which was causing the error for C++ style comments in C code. If I take that option out, as expected, compiler does not give errors for these comments anymore. Thanks for your speedy reply.
0 Kudos
SergeyKostrov
Valued Contributor II
819 Views
I am unable to reproduce the issue. I am using VS2010.

...
#include

// XXX There should be a macro to signal with C++ revision is used.
// XXX This function is in the C++1x revision.
/* Register a function to be called when `quick_exit' is called. */
...
Did I miss something?


No. Thanks for the test.
0 Kudos
Reply