[Insight-users] NumericTraits level 3 warnings on VS 2008
Niels Dekker
niels-xtk at xs4all.nl
Thu Nov 27 09:42:26 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
Please take a look at the attached patch. Is it okay if I commit it to
Insight/Code/Common?
Kind regards,
--
Niels Dekker
http://www.xs4all.nl/~nd/dekkerware
Scientific programmer at LKEB, Leiden University Medical Center
-------------- next part --------------
A non-text attachment was scrubbed...
Name: itkNumericTraits_disable_C4309.patch
Type: application/octet-stream
Size: 858 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20081127/21c8ca43/attachment-0001.obj>
More information about the Insight-users
mailing list