[Paraview-developers] Problem in the ParaView code

Moreland, Kenneth kmorel at sandia.gov
Mon Sep 12 10:21:49 EDT 2005


<countergrumble>
 
gcc is doing exactly as it should.  It knows very well the order in
which the operations should occur.  If it didn't, it would have given an
error.  A warning is specifically for something that is technically
correct but can easily lead to a problem if the programmers are not very
careful.
 
In this case, although the meaning is clear to the compiler, it is not
at all clear to a human without careful consideration.  Case in point:
Andy didn't fix this himself because he was not positive on the order of
operations.  Had Andy (or anyone else, not to pick on Andy) been editing
this code for other reasons and was not alerted by the warning, he could
easily have misinterpreted the line of code.
 
This warning is similar to the one given when you use an assignment
instead of comparison inside a conditional: 
 
    if (foo = bar())
 
Although the expression is unambiguous (call function bar, put it's
result in foo, then check if foo is non-zero), it's considered dangerous
due to the visual similarity of operators = and ==.  This particular
warning has saved me many, many hours of debugging.  And that's what
warnings are all about.
 
</countergrumble>
 
-Ken


________________________________

	From: paraview-developers-bounces+kmorel=sandia.gov at paraview.org
[mailto:paraview-developers-bounces+kmorel=sandia.gov at paraview.org] On
Behalf Of Thompson, David C
	Sent: Saturday, September 10, 2005 2:09 PM
	To: Andy Cedilnik; ParaViewDev
	Subject: RE: [Paraview-developers] Problem in the ParaView code
	
	

	<grumble>It's a perfectly valid expression; since the assignment
	is parenthesized, it must occur before the multiplication. And
	the value of any assignment statement is the value assigned.
	So gcc should know better than to emit a warning!</grumble>
	

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/mailman/private/paraview-developers/attachments/20050912/ba5157bc/attachment.htm


More information about the Paraview-developers mailing list