This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
abs function question
- From: Steve Ellcey <sje at cup dot hp dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Mon, 28 Jul 2003 17:13:42 -0700 (PDT)
- Subject: abs function question
- Reply-to: sje at cup dot hp dot com
I am currently running into a problem with the function abs and the
header std_cstdlib.h. This file contains the lines:
namespace std
{
using ::abs
}
The problem is that my system's stdlib.h header file is smart enough to
not do an extern declaration for abs if it is in C++ mode and instead
does an inline declaration of the abs function. It only does an extern
declaration if it is in C mode. Thus I get an error on the 'using ::abs'
line. I could handle this with fixheaders but I was wondering if there
is any reason one couldn't replace
using ::abs
with
inline int abs(int __i) { return __i >= 0 ? __i : -__i; }
For that matter would it also make sense to replace
inline long abs(long __i) { return labs(__i); }
with
inline long abs(long __i) { return __i >= 0 ? __i : -__i; }
We already use this inline for the type 'long long'.
Steve Ellcey
sje@cup.hp.com