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

pragma unused

inteluser
Beginner
867 Views

I am looking for a way to suppress warning #177: "variable was declared but never referenced" for certain variables throughout my code. The GCC compiler has __attribute__((unused)) for this.

According to the documentation Composer XE 12.1 should allow me to use "#pragma unused". However, using this approach the compiler issues the warning: "warning #161: unrecognized #pragma unused".

0 Kudos
5 Replies
Judith_W_Intel
Employee
867 Views

Does attribute unused not work with our compiler? If so can you provide an example and tell us which version of the compiler you are using?

I tried a simpleexample with version 12.1 and it seems towork for me:

sptxl8-446> cat att.c

#ifdef OK
static void foo() __attribute__((unused));
#endif

static void foo()
{
#ifdef OK
int j __attribute__((unused));
#else
int j;
#endif
}
sptxl8-447> icpc -Wremarks -c att.c
att.c(13): remark #177: variable "j" was declared but never referenced
int j;
^

att.c(8): remark #177: function "foo" was declared but never referenced
static void foo()
^

sptxl8-448> icpc -Wremarks -DOK -c att.c
sptxl8-449>


thanks
Judy
0 Kudos
inteluser
Beginner
867 Views

I use the following version together with Visual Studio 2010 on Windows 7 64bit.

c:\\Program Files (x86)\\Intel\\Composer XE 2011 SP1\\bin\\intel64\\icl

Intel C++ Intel 64 Compiler XE for applications running on Intel 64, Version 12.1.3.300 Build 20120130

I've tried your simple example:

3> main.cpp
3>main.cpp(5): error : expected a "{"
3> static void foo() __attribute__((unused));
3> ^
3>
3>main.cpp(8): warning #12: parsing restarts here after previous syntax error
3> {
3> ^
3>
3>main.cpp(9): error : expected a ";"
3> int j __attribute__((unused));
3> ^
0 Kudos
TimP
Honored Contributor III
867 Views
Unfortunately, gcc extensions such as __attribute__ don't work with the Microsoft-compatible Windows compiler. You may find the mingw 64-bit gcc compiler useful.
0 Kudos
jimdempseyatthecove
Honored Contributor III
867 Views
#define _UNUSED_(x) (void)x;
void foo(int a, int b)
{
++a;
_UNUSED_(b)
}

Jim Dempsey
0 Kudos
inteluser
Beginner
867 Views
0 Kudos
Reply