[mythtv] Should llabs() be used instead of abs() for long long int?

Lawrence Rust lvr at softsystem.co.uk
Wed Jul 4 19:01:43 UTC 2012


On Wed, 2012-07-04 at 12:22 -0400, Daniel Thor Kristjansson wrote:
> On 07/04/2012 10:50 AM, Matthew Parris wrote:
> > Thanks, Gary, for the reply.  Do you think the project would accept a
> > patch to change from abs to llabs?  Are there benefits of using abs that
> > couldn't be achieved with llabs?
> 
> As long as you explain why it is needed in the ticket and include the
> proper header in the file it will be accepted.
> 
> I think "long long" isn't a C++98 type, though it in practice
> is supported by all C++ compilers since it is a C99 type and
> a C++11 type. I guess compilers also adding abs(long long) to
> their libraries is not universal and hence the error.

IMHO the most compatible solution is to keep with abs and rely upon
polymorphism i.e.

#include <cstdlib>
...
	sometype_t x; // maybe long long
	std::abs(x);

It's not a good idea to use abs without a namespace due to conflicting
(macro) implementations (M$ et al).  This covers most C++ compilers
since ~2000 and the the C++0x N2798 quasi-standard which added the
signature:

long long abs(long long);

and compatibility with C1x N1570 <stdlib.h> which included llabs.
However, C1x isn't widespread so relying on it is dubious.

-- 
Lawrence


More information about the mythtv-dev mailing list