[Insight-developers] warning C4267 on VC7

Andy Cedilnik andy.cedilnik@kitware.com
19 Feb 2003 17:16:22 -0500


Hi again,

I played with VC7 and looks like one of the problems is that VC7 does
not provide output operator for __w64 or whatever size_t will be on 64
bit platforms. So, If you look at this example:

int main()
{
	std::string s = "dshfljk";
	std::cout << "Size of s: " << s.size() << std::endl;
}

you will get warning. However:

int main()
{
	std::string s = "dshfljk";
	std::cout << "Size of s: " 
		<< static_cast<unsigned long>(s.size()) << std::endl;
}

And the warning is gone.

				Andy


On Wed, 2003-02-19 at 16:24, Andy Cedilnik wrote:
> I think disabling C4276 would be a wrong way to go. The right way is to
> go through ITK and fixing all the places where warning happens. I know
> that is just about everywhere, but ignoring this warning might lead into
> trouble sometimes down the road.
> 
> In VTK, we fixed most of these places. Fortunately at that time VTK did
> not use STL, so the only place where this happened was when using
> strlen(x).
> 
> Now, the reason why it would be bad to ignore the warning is simple.
> Right now you are using mostly 32 bit platforms. size_t and unsigned int
> are the same. Once you switch to 64 bit platform, that is not the case
> any more. So, you will have a std::vector with 2^32 elements, you will
> ask it for size and you will get 0 or something.
> 
> By fixing the warnings to some meaningful solutions (for example use
> size_t or std::vector<bla>::size_type or whatever), you can be at least
> a little bit sure that your thing will not blowup when somebody tries on
> a large dataset.