This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

stdlib.h abs(long) overload?


I discovered that at least with Fedora 20 combination of libstdc++ 4.8.2 and glibc 2.18, including stdlib.h does not make available an abs(long) overload to abs(int). That is, in a 64 bit environment,

#include <iostream>
#include <stdlib.h>
int main() {
    long n1 = -4294967296;
    long n2 = abs(n1);
    std::cout << n1 << " " << n2 << "\n";
}

prints

-4294967296 0

instead of

-4294967296 4294967296

It works correctly when using cstdlib and std::abs instead, and my reading of the C++ standards (both 03 and 11) is that including stdlib.h should make the overload available in the global namespace.

The __CORRECT_ISO_CPP_STDLIB_H_PROTO in the source (apparently only used for Solaris) makes me assume that this is a known issue. Is the take of libstdc++ on this that it is a bug in glibc that needs to be fixed there? (Not sure whether the alternative of working around the glibc shortcoming in libstdc++, by providing a stdlib.h wrapper, say, would be feasible at all.)

Clarification welcome,
Stephan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]