[Insight-developers] A massive number of new warnings

Williams, Norman K norman-k-williams at uiowa.edu
Fri Jan 7 09:43:32 EST 2011


UINT(-1) is the same as UINT_MAX, but I can't imagine using it as a shorthand for UINT_MAX.  Of course we're all computer scientists and know that the most significant bit of an integer is the sign, and consequently the rules of 2's complement math define UINT(-1) and UINT_MAX as the same bit pattern, but…

It is always the case that UINT(-1) == -1 in C++ as far as I know, but keeping your signed and unsigned values and variables straight is good programming practice, because it prevents you from getting into trouble down the line because (UINT-1) < 0 is false.

One needs to be consistent in writing code, and the types you choose need to mean something, particularly when you're writing a library for others to use.  I can guarantee you that if you poll the people on the ITK Users list, many of them aren't well schooled in the ins and outs of 2's complement mathematics.

From: Bradley Lowekamp <blowekamp at mail.nih.gov<mailto:blowekamp at mail.nih.gov>>
Date: Fri, 7 Jan 2011 09:30:01 -0500
To: Luis Ibanez <luis.ibanez at kitware.com<mailto:luis.ibanez at kitware.com>>
Cc: ITK <insight-developers at itk.org<mailto:insight-developers at itk.org>>, Hans Johnson <hans-johnson at uiowa.edu<mailto:hans-johnson at uiowa.edu>>
Subject: Re: [Insight-developers] A massive number of new warnings

Luis,

Isn't UINT(-1) a short hand for the max unsigned int? Isn't this behavior well defined by the C++ standard? Could the only thing wrong with the code be there is just an implicit case, and not an explicit one? You may have changed what the code was doing.

Brad


On Jan 7, 2011, at 8:58 AM, Luis Ibanez wrote:

Brad,

I'm all for treating Warnings as errors,
and agree with Dave's point that it is the way to
prevent them from being dismissed by developers.

In many cases they are hinting us to locate real errors.

For example, in this patch:

http://review.source.kitware.com/#change,679

The warnings in openjpeg were revealing bugs in the
API of many functions.

In particular, functions whose return type is declared
as UINT32, and the code of the implementations return
"-1", and code down the line compares against "-1".

http://review.source.kitware.com/#patch,sidebyside,679,1,Utilities/openjpeg/openjpeg.c

Those are real bugs,
that were hinted by warnings.


     Luis



========================================================

Bradley Lowekamp

Lockheed Martin Contractor for

Office of High Performance Computing and Communications

National Library of Medicine

blowekamp at mail.nih.gov<mailto:blowekamp at mail.nih.gov>


_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Kitware offers ITK Training Courses, for more information visit: http://kitware.com/products/protraining.html Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ Follow this link to subscribe/unsubscribe: http://www.itk.org/mailman/listinfo/insight-developers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/mailman/private/insight-developers/attachments/20110107/c758ea81/attachment.htm>


More information about the Insight-developers mailing list