This is the mail archive of the 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]

Re: abs function question

Well, it looks like I messed up.  The header does appear to work as is.
I think the problem I was seeing was a side effect of the file level
include guards conflicting with HP system ifdefs and now that they have
been changed it all seems to work fine and no change is required.

I think part of my argument is still valid for some systems though,

namespace std {
  inline int abs(int __i) { return __i >= 0 ? __i : -__i; }
  inline long abs(long __i) { return __i >= 0 ? __i : -__i; }

be more efficient then:

namespace std {
  using ::abs
  inline long abs(long __i) { return labs(__i); }

It looks like I already get inlined behaviour for 'int abs' because my
system header defines it as an inline function and 'using ::abs'
preserves that but if abs were just defined as an external function call
then the C++ version would be a function call too.  labs is not defined
as an inline function though so I wind up making a function call for
labs or for abs(long).  I guess one could argue that if my system header
defined labs as an inline function then I wouldn't see a call to it and
so it isn't up to this header file to change that behaviour but it seems
so tempting to just do an inline function definition in std_cstdlib.h
that doesn't call the C versions.  Is there any reason why we couldn't
(or shouldn't)?

Steve Ellcey

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