[vtk-developers] unsigned/signed comparison

Marcus D. Hanwell marcus.hanwell at kitware.com
Wed Dec 23 17:11:51 EST 2009

On Wednesday 23 December 2009 16:49:16 David Doria wrote:
> Is the preferred way to do this comparison:
> for(unsigned int i = 0; i < polygon2->GetNumberOfPoints(); i++)
> to use a signed int for the counter:
> for(int i = 0; i < polygon2->GetNumberOfPoints(); i++)
> or cast the compare value as an unsigned int:
> for(unsigned int i = 0; i < static_cast<unsigned
> int>(polygon2->GetNumberOfPoints()); i++)
I think you are best off using the return type for the function giving you the 
size of the object you are looping over. For STL types this is often size_t 
and I believe is signed on some platforms and not on others. So the only way 
to be sure to get it right is to use size_t.

Marcus D. Hanwell, Ph.D.
R&D Engineer, Kitware Inc.
(518) 881-4937

More information about the vtk-developers mailing list