Why does PGI give an overloaded abs() error?

The following test code compiles with all of our known compilers except PGI (version 7 through 10.6 tried):

$ cat SimpleTestAbsBug.cc

/* abs example */
#include <stdlib.h>
#include

int main ()
{
double ATOL;
double VL;
VL = 9.9999999;
ATOL = abs(VL);
return 0;
}

$ CC -c SimpleTestAbsBug.cc
“SimpleTestAbsBug.cc”, line 10: error: more than one instance of overloaded
function “abs” matches the argument list:
function “abs(int)”
function “std::abs(long)”
argument types are: (double)
ATOL = abs(VL);
^

If the "#include " line is commented out then the code will compile w/o error but the real code this was taken from requires the string headers.

Hi David,

By default the PGI C++ compiler includes the std namespace. Hence, you’re getting a conflict between the std::abs and the abs defined in the C header file stdlib.h. Since “VL” is a double and can be cast to either an int or a long, the compiler doesn’t know which abs you want.

Your options are to add the flag “–no_using_std” to tell the compiler to not use the std namespace by default, or explicitly cast VL to either int or long.

Hope this helps,
Mat

% cat test.cpp
/* abs example */
#include <stdlib.h>
#include <string>

int main ()
{
double ATOL;
double VL;
VL = 9.9999999;
ATOL = abs((long)VL);
return 0;
}

% pgcpp test.cpp
"test.cpp", line 7: warning: variable "ATOL" was set but never used
  double ATOL;
         ^