PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

Free OpenACC Course

Why does PGI give an overloaded abs() error?

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling
View previous topic :: View next topic  
Author Message
David Gunter



Joined: 15 Sep 2005
Posts: 25

PostPosted: Thu Sep 30, 2010 2:48 pm    Post subject: Why does PGI give an overloaded abs() error? Reply with quote

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 <string>

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 <string>" line is commented out then the code will compile w/o error but the real code this was taken from requires the string headers.
Back to top
View user's profile
mkcolg



Joined: 30 Jun 2004
Posts: 6697
Location: The Portland Group Inc.

PostPosted: Thu Sep 30, 2010 3:32 pm    Post subject: Reply with quote

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

Code:
% 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;
         ^
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Programming and Compiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group