Boost logo

Boost Users :

Subject: Re: [Boost-users] [math] Warning in math/common_factor_rt.hpp
From: Gabriel Redner (gredner_at_[hidden])
Date: 2010-07-01 12:14:53


Investigating a bit further, I discovered that we are actually passing
-funsigned-char to the compiler. This causes a problem because:

common_factor_rt.hpp:329
    BOOST_PRIVATE_GCD_SF( char, unsigned char ); // should work even if unsigned

This macro expands into:
common_factor_rt.hpp:317
#define BOOST_PRIVATE_GCD_SF( St, Ut ) \
    template < > struct gcd_optimal_evaluator<St> \
    { St operator ()( St a, St b ) const { Ut const a_abs = \
    static_cast<Ut>( a < 0 ? -a : +a ), b_abs = static_cast<Ut>( \
    b < 0 ? -b : +b ); return static_cast<St>( \
    gcd_optimal_evaluator<Ut>()(a_abs, b_abs) ); } }

The expression 'a < 0' is always false if 'a' is unsigned, so the
compiler issues a warning (if warnings are turned high enough).

My impression is that this code should be considered incorrect -
making assumptions about the signed-ness of char is not portable. I
do not understand why the comment suggests that this "should work".

-Gabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net