This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC 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]

cstdlib declarations of ::abs


Hi,

I have a question about the intended declarations of ::abs in gcc when
we #include <cstdlib>.

I am aware that the standard does not require cstdlib to provide any
declaration of ::abs at all, and that compliant code should either use
std::abs, or #include <stdlib.h> (deprecated) before using ::abs. So,
I expected cstdlib to either:
1. not provide ::abs at all, or
2. provide all the overloads of abs (::abs(int), ::abs(long),
::abs(long long)) - the same set that are required to be provided if
we include <stdlib.h>

In practice, using gcc 5.4.0/6.3.0 on both OSX 10.10.5 and Fedora Core
17 (glibc 2.15), I was surprised to find that including cstdlib
provides only ::abs(int), as per the C library spec. It therefore
seems easy to end up calling ::abs(int) with a long by mistake if you
mistakenly believe stdlib.h was included. (I realise that -Wconversion
would also catch this).

I'm not suggesting this is an error, for the reasons above. My question is:
 - Is this intentional behaviour?
 - If not, is it possible/useful to change it to one of the above?


I also looked at the behaviour of #include <stdlib.h>, which AFAIK is
required to provide all the overrides of ::abs, and on my test systems
it does indeed do that with gcc 6.3.0 (since bug 60401 was fixed).


Also just for information, with llvm 3.9.0 clang++/libc++, #include
<cstdlib> and #include <stdlib.h> both seem to provide all the
overloads of ::abs.


Thanks
Dave


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