Message: graphics_reps\src\BooleanProcessor.src question Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question graphics_reps\src\BooleanProcessor.src question 

Forum: Geometry
Date: 27 Jan, 2012
From: Elena Novikova <Elena Novikova>

During compilation from scratch of the ver. 9.5 geant4 code (using Visual Studio 2008 Express), I saw a warning that I believe warrants some investigation. The file


has the following lines:

          edges.push_back(ExtEdge(k[1], k[4], i, -(edges.size()+1), -1));
          edges.push_back(ExtEdge(k[4], k[1], i, -(edges.size()-1), -1));

And a few similar lines later in the code.

My concern is related to the warning my compiler issues:

  e:\geant4\g4-vs2008-ver9.5\geant4_9_5\source\graphics_reps\src\BooleanProcessor.src(1553) : warning C4146: unary minus operator applied to unsigned type, result still unsigned

This tells me that it is possible that the logic of the code assumes that the expression -(edges.size()-1) is assumed to be allowed to be negative. However, it will remain non-negative because the value of edges.size() is of the type “unsigned” (specifically, “size_t”). Subtracting 1 from it doesn’t change its type. After that, applying unary minus operand, as the compiler says, will not change its type either, and the resulting action of the code may be unpredictable. It is my understanding that to achieve proper functionality one need to cast the edges.size(), as say, static_cast<int>( edges.size()), and then all result immediately will go into the realm if integers and applying a unary minus to say, a value of 5 will result in -5 and not in some crazy value.

Since I did not follow the logic of each step in this code, I may be mistaken in my interpretation of the author’s intention. If the author indeed wanted to operate in unsigned numbers only, the code is correct. However, if the author wanted to have the full realm of integers (why else would you apply a unary minus?), there may be an imperfection in the code. (Or, simply put, it will not work as intended.)


--Elena Novikova,

Naval Research Laboratory

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

1 None: Re: graphics_reps\src\BooleanProcessor.src question   (John Allison - 27 Jan, 2012)
 Add Message Add Message
to: "graphics_reps\src\BooleanProcessor.src question"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews

[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]