Boost logo

Boost :

Subject: Re: [boost] [gil] gcc fail with simple code
From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2018-03-28 19:30:51


On 28 March 2018 at 21:23, Andrey Semashev via Boost
<boost_at_[hidden]> wrote:
> On 03/28/18 22:10, Stefan Seefeld via Boost wrote:
>> On 28.03.2018 14:48, Christian Henning via Boost wrote:
>>>>
>>>> I would suggest casting to unsigned first and then performing the math.
>>>
>>> I assume this is what you meant:
>>>
>>> template <> struct channel_convert_to_unsigned<bits32s> : public
>>> std::unary_function<bits32s,bits32> {
>>> typedef bits32 type;
>>> type operator()(bits32s x) const
>>> {
>>> uint32_t a = static_cast<uint32_t>(x);
>>> a += (1 << 31);
>>>
>>> return static_cast<bits32>(a);
>>> }
>>> };
>>
>>
>> Or simply replace `static_cast<bits32>(x+(1<<31))` by
>> `static_cast<bits32>(x)+(1<<31)` (i.e., cast `x` rather than the full
>> expression).
>
>
> Rather:
>
> static_cast<bits32>(x)+(static_cast<bits32>(1)<<31)
>
> to make it compatible with older C++ versions.

I think Andrey's version also sticks out and documents the danger better,
than 'cosmetic' shuffle of one bracket.

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk