Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've got a persistent warning across all the compilers I've tried.

It has to do with the srf var in the "What have you tried" section.

Basically the compiler doesn't know that srf can't be very big.

Specifically, it is limited to the difference in bit depth between one pixel and another which is practically limited to 63 max for a 64-bit word, 31 for a 32-bit word, etc. I have static_asserts elsewhere that limit bit_depth.

I know it will never overflow, but (hopefully without supressing warnings) how do I tell the compiler it can't be greater than some value such that this warning won't appear?

What I have tried:

C++
// converts one channel's bit depth to another
template <typename ChannelLhs,typename ChannelRhs>
constexpr inline static typename ChannelRhs::int_type convert_channel_depth(typename ChannelLhs::int_type v) {
    typename ChannelRhs::int_type rv=0;
    if(ChannelLhs::bit_depth==0 || ChannelRhs::bit_depth==0) return 0;
    const uint8_t srf = (int)ChannelLhs::bit_depth-(int)ChannelRhs::bit_depth;
    if(0<srf) {
        // below generates right shift count warning GCC/MSVC
        rv = (typename ChannelRhs::int_type)(v>>(0>srf?0:srf));
        rv = clamp(rv,ChannelRhs::min,ChannelRhs::max);
        //float vs = v*ChannelLhs::scaler;
        //rv = clamp((typename ChannelRhs::int_type)(vs*ChannelRhs::scale+.5),
        //            ChannelRhs::min,ChannelRhs::max);
    } else if(0>srf) {
        //rv = (typename ChannelRhs::int_type)(v<<(0<srf?0:-srf));
        //rv = clamp(rv,ChannelRhs::min,ChannelRhs::max);
        float vs = v*ChannelLhs::scaler;
        rv = clamp((typename ChannelRhs::int_type) 
             (vs*ChannelRhs::scale+.5),ChannelRhs::min,ChannelRhs::max);
    } else
        rv = (typename ChannelRhs::int_type)(v);
    return rv;
}
Posted
Updated 4-Oct-23 3:04am
v2

1 solution

Have you tried ANDing it with 111111b? Since the value can't be bigger than 63 that might shut the compiler up?
 
Share this answer
 
Comments
honey the codewitch 4-Oct-23 9:43am    
Ah, I'll give it a shot
honey the codewitch 4-Oct-23 9:49am    
didn't work

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900