[Insight-users] NumericTraits level 3 warnings on VS 2008

Denis Shamonin dshamoni at science.uva.nl
Thu Nov 27 10:06:52 EST 2008


> Denis Shamonin wrote:
>> I've compile warnings on VS 2008 (Itk 3.10.0) for
>> Class:
>> NumericTraits<char> : public vcl_numeric_limits<char>
>>
>> Function:
>>  static char min() { return char(255) < 0 ? -128 : 0; }
>>  static char max() { return char(255) < 0 ? 127 : 255; }
>>
>> Warnings:
>> itk3\include\common\itkNumericTraits.h(165) : warning C4310: cast
>> truncates constant value
>> itk3\include\common\itkNumericTraits.h(166) : warning C4310: cast
>> truncates constant value
>>
>> Should it be changed to
>>  static char min() { const char minValue=255;
>>    return char(minValue) < 0 ? -128 : 0; }
>>  static char max() { const char maxValue=255;
>>    return char(maxValue) < 0 ? 127 : 255; }
>
> Denis, I agree that those warnings are annoying, but I don't really
> understand your proposed solution either, casting a char to a char.
> Also I think your approach might trigger another warning on MSVC 9 (VS
> 2008), "C4309: 'initializing' : truncation of constant value".
>
>
> I think it would be better to just locally disable warning C4310, in
> itkNumericTraits.h:
>
>   #ifdef _MSC_VER
>   #pragma warning (push)
>   #pragma warning (disable: 4310) // cast truncates constant value
>   #endif
>
>   static char min() { return char(255) < 0 ? -128 : 0; }
>   static char max() { return char(255) < 0 ? 127 : 255; }
>
>   #ifdef _MSC_VER
>   #pragma warning (pop)
>   #endif

Niels, your solution looks fine for me. I am not sure if you have to use:
#ifdef _MSC_VER
#if _MSC_VER > 1400 // For MS Visual Studio higher than Visual C++ 2005
...

-Denis Shamonin



More information about the Insight-users mailing list