stdlib.h abs(long) overload?
Jonathan Wakely
jwakely.gcc@gmail.com
Mon Mar 3 16:55:00 GMT 2014
On 3 March 2014 16:40, Stephan Bergmann <sbergman@redhat.com> wrote:
> 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.)
Yes, we need cooperation from glibc to solve it, which is certainly
possible, and should be done, we just need to discuss it with them.
Feel free to report it to GCC's bugzilla as a reminder to do that, and
I'll try to ensure it happens for the next release.
More information about the Libstdc++
mailing list