diff --git a/ChangeLog b/ChangeLog index aabc1dd27d5679ab281fe6f490e1b038ab6b96ae..835c113f4ecb85358c27e6c8739ee8df7922cc37 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2008-07-17 Lynn Garren <garren@fnal.gov> + + * various changes in Random to keep gcc 4.3 happy + +2008-07-16 Lynn Garren <garren@fnal.gov> + + * Matrix/src/SymMatrix.cc, Matrix.cc, DiagMatrix.cc, MatrixLinear.cc: + Iterators were set to a nonexistent memory location in many places. + Even though the iterators were not used, this operation is not allowed + and causes problems with the newer VC++ compilers. + In some cases, a more efficient rewrite was possible. + ============================== 01.05.08 Release CLHEP-2.0.3.3 ============================== diff --git a/Evaluator/ChangeLog b/Evaluator/ChangeLog index ab48c2cbf12ea0829a8f12c51ca15810fbae2112..f252dd6185172be9a1327711f34c33ef33cede06 100755 --- a/Evaluator/ChangeLog +++ b/Evaluator/ChangeLog @@ -1,3 +1,8 @@ +2008-07-16 Lynn Garren <garren@fnal.gov> + + * src/Evaluator.cc: Fix non ISO C++ compliant cast from pointer to + function to void*, which is a pointer to an object. + ============================== 01.05.08 Release CLHEP-2.0.3.3 ============================== diff --git a/Evaluator/src/Evaluator.cc b/Evaluator/src/Evaluator.cc index 4654e85a06741f04ea61ab16dd8ac4f4add52edc..e2b64847bb8b574f80384960074112f6b6083d4a 100755 --- a/Evaluator/src/Evaluator.cc +++ b/Evaluator/src/Evaluator.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: Evaluator.cc,v 1.2 2003/08/13 20:00:10 garren Exp $ +// $Id: Evaluator.cc,v 1.2.4.1 2008/07/17 19:00:45 garren Exp $ // --------------------------------------------------------------------------- #include "CLHEP/Evaluator/defs.h" @@ -16,16 +16,22 @@ #include <stdlib.h> // for strtod() //--------------------------------------------------------------------------- +// Fix non ISO C++ compliant cast from pointer to function +// to void*, which is a pointer to an object +typedef void (*voidfuncptr)(); struct Item { enum { UNKNOWN, VARIABLE, EXPRESSION, FUNCTION } what; double variable; string expression; - void *function; + // Fix non ISO C++ compliant cast from pointer to function + // to void*, which is a pointer to an object + //void *function; + voidfuncptr function; Item() : what(UNKNOWN), variable(0),expression(), function(0) {} Item(double x) : what(VARIABLE), variable(x),expression(), function(0) {} Item(string x) : what(EXPRESSION),variable(0),expression(x),function(0) {} - Item(void *x) : what(FUNCTION), variable(0),expression(), function(x) {} + Item(voidfuncptr x) : what(FUNCTION), variable(0),expression(), function(x) {} }; typedef char * pchar; @@ -646,29 +652,31 @@ void Evaluator::setVariable(const char * name, const char * expression) { setItem("", name, Item(expression), (Struct *)p); } //--------------------------------------------------------------------------- +// Fix non ISO C++ compliant cast from pointer to function +// to void*, which is a pointer to an object void Evaluator::setFunction(const char * name, double (*fun)()) -{ setItem("0", name, Item((void *)fun), (Struct *)p); } +{ setItem("0", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); } void Evaluator::setFunction(const char * name, double (*fun)(double)) -{ setItem("1", name, Item((void *)fun), (Struct *)p); } +{ setItem("1", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); } void Evaluator::setFunction(const char * name, double (*fun)(double,double)) -{ setItem("2", name, Item((void *)fun), (Struct *)p); } +{ setItem("2", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); } void Evaluator::setFunction(const char * name, double (*fun)(double,double,double)) -{ setItem("3", name, Item((void *)fun), (Struct *)p); } +{ setItem("3", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); } void Evaluator::setFunction(const char * name, double (*fun)(double,double,double,double)) -{ setItem("4", name, Item((void *)fun), (Struct *)p); } +{ setItem("4", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); } void Evaluator::setFunction(const char * name, double (*fun)(double,double,double,double,double)) -{ setItem("5", name, Item((void *)fun), (Struct *)p); } +{ setItem("5", name, Item(reinterpret_cast<voidfuncptr>(fun)), (Struct *)p); } //--------------------------------------------------------------------------- bool Evaluator::findVariable(const char * name) const { diff --git a/Random/ChangeLog b/Random/ChangeLog index b5dfd5a8e28b1287e0449d7c831dd8c0452783ad..512056adc3ad6b05326149f10cb1b6f55011da33 100755 --- a/Random/ChangeLog +++ b/Random/ChangeLog @@ -1,3 +1,23 @@ +2008-07-17 Lynn Garren <garren@fnal.gov> + + * add explicit parentheses in various places to keep gcc 4.3 happy + + * src/RandEngine.cc: change how the compiler decides how to implement flat() + + * test/testRandDists.cc: force variables to be in memory so + testRandGeneral() behaves the same with both gcc 4.3 and 3.4. + + * Random/src/DRand48Engine.cc,RandEngine.cc: + Remove (incorrect) implementation of private, unused, copy constructor + and operator=. + + * Random/src/drand48.src: + The implementaton of the drand48_iterate method contained a problematic + "if (sizeof (unsigned short int) == 2) { } else {}" structure. + Code contained in the else portion had unintended side effects. + We have retained only the code in the if portion, which should work + on all machines. + ============================== 01.05.08 Release CLHEP-2.0.3.3 ============================== diff --git a/Random/src/DRand48Engine.cc b/Random/src/DRand48Engine.cc index a82c0e5ccca191bcf95d52c131496845ab99fda7..0fbd9eadb794dc88a29424809437238181ce9ad6 100755 --- a/Random/src/DRand48Engine.cc +++ b/Random/src/DRand48Engine.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: DRand48Engine.cc,v 1.4.4.2 2005/04/15 16:32:53 garren Exp $ +// $Id: DRand48Engine.cc,v 1.4.4.3 2008/07/17 19:00:45 garren Exp $ // ----------------------------------------------------------------------- // HEP Random // --- DRand48Engine --- @@ -94,29 +94,6 @@ DRand48Engine::DRand48Engine(std::istream& is) DRand48Engine::~DRand48Engine() {} -DRand48Engine::DRand48Engine(const DRand48Engine &p) -{ - // Assignment and copy of DRand48Engine objects may provoke - // undesired behavior in a single thread environment. - - std::cerr << "!!! WARNING !!! - Illegal operation." << std::endl; - std::cerr << "- Copy constructor and operator= are NOT allowed on " - << "DRand48Engine objects -" << std::endl; - *this = p; -} - -DRand48Engine & DRand48Engine::operator = (const DRand48Engine &p) -{ - // Assignment and copy of DRand48Engine objects may provoke - // undesired behavior in a single thread environment. - - std::cerr << "!!! WARNING !!! - Illegal operation." << std::endl; - std::cerr << "- Copy constructor and operator= are NOT allowed on " - << "DRand48Engine objects -" << std::endl; - *this = p; - return *this; -} - void DRand48Engine::setSeed(long seed, int) { srand48( seed ); diff --git a/Random/src/JamesRandom.cc b/Random/src/JamesRandom.cc index 81ff20d342ce412decff36ed345888562ab071d8..ea8f58482102ce00576784740380c76ece9746bd 100755 --- a/Random/src/JamesRandom.cc +++ b/Random/src/JamesRandom.cc @@ -1,4 +1,4 @@ -// $Id: JamesRandom.cc,v 1.4.4.2 2005/04/15 16:32:53 garren Exp $ +// $Id: JamesRandom.cc,v 1.4.4.3 2008/07/17 19:00:45 garren Exp $ // -*- C++ -*- // // ----------------------------------------------------------------------- @@ -320,8 +320,8 @@ void HepJamesRandom::flatArray(const int size, double* vect) } HepJamesRandom::operator unsigned int() { - return (unsigned int)(flat() * exponent_bit_32) & 0xffffffff | - ((unsigned int)( u[i97] * exponent_bit_32)>>16) & 0xff; + return ((unsigned int)(flat() * exponent_bit_32) & 0xffffffff ) | + (((unsigned int)( u[i97] * exponent_bit_32)>>16) & 0xff); } std::ostream & HepJamesRandom::put ( std::ostream& os ) const { diff --git a/Random/src/RandEngine.cc b/Random/src/RandEngine.cc index 27fce6e3826a5c4fd8070641bac52844d53331b5..850a394a9445bd6f2f8dc7576c968615bf2cb2ec 100755 --- a/Random/src/RandEngine.cc +++ b/Random/src/RandEngine.cc @@ -1,4 +1,4 @@ -// $Id: RandEngine.cc,v 1.4.4.4 2005/04/15 16:32:53 garren Exp $ +// $Id: RandEngine.cc,v 1.4.4.5 2008/07/17 19:00:45 garren Exp $ // -*- C++ -*- // // ----------------------------------------------------------------------- @@ -124,30 +124,6 @@ RandEngine::RandEngine(std::istream& is) RandEngine::~RandEngine() {} -RandEngine::RandEngine(const RandEngine &p) -: mantissa_bit_32( pow(0.5,32.) ) -{ - // Assignment and copy of RandEngine objects may provoke - // undesired behavior in a single thread environment. - - std::cerr << "!!! WARNING !!! - Illegal operation." << std::endl; - std::cerr << "- Copy constructor and operator= are NOT allowed on " - << "RandEngine objects -" << std::endl; - *this = p; -} - -RandEngine & RandEngine::operator = (const RandEngine &p) -{ - // Assignment and copy of RandEngine objects may provoke - // undesired behavior in a single thread environment. - - std::cerr << "!!! WARNING !!! - Illegal operation." << std::endl; - std::cerr << "- Copy constructor and operator= are NOT allowed on " - << "RandEngine objects -" << std::endl; - *this = p; - return *this; -} - void RandEngine::setSeed(long seed, int) { theSeed = seed; @@ -281,8 +257,11 @@ void RandEngine::showStatus() const iS = RAND_MAX + 1; iK = 1; // int StoK = S; - int StoK = iS; - if ( (RAND_MAX >> 32) == 0) { + int StoK = iS; + // The two statements below are equivalent, but some compilers + // are getting too smart and complain about the first statement. + //if ( (RAND_MAX >> 32) == 0) { + if( (unsigned long) (RAND_MAX) <= (( (1uL) << 31 ) - 1 ) ) { iK = 2; // StoK = S*S; StoK = iS*iS; diff --git a/Random/src/drand48.src b/Random/src/drand48.src index ad17bd4dad50cf0e5cbcf2b2c281f5611cb784d3..ec6545718b2720eae4df16ca1150c5b3fe0e99ae 100755 --- a/Random/src/drand48.src +++ b/Random/src/drand48.src @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: drand48.src,v 1.1.1.1.4.1 2004/04/29 00:20:37 garren Exp $ +// $Id: drand48.src,v 1.1.1.1.4.2 2008/07/17 19:00:45 garren Exp $ // --------------------------------------------------------------------------- // // This code is based on a code extracted from GNU C Library 2.1.3 with @@ -145,25 +145,15 @@ int drand48_iterate (unsigned short int xsubi[3], drand48_data *buffer) 48 bits. Because we compute the modulus it does not care how many bits really are computed. */ - if (sizeof (unsigned short int) == 2) { - X = (u_int64_t)xsubi[2] << 32 | (u_int64_t)xsubi[1] << 16 | xsubi[0]; - a = ((u_int64_t)buffer->a[2] << 32 | (u_int64_t)buffer->a[1] << 16 - | buffer->a[0]); + X = (u_int64_t)xsubi[2] << 32 | (u_int64_t)xsubi[1] << 16 | xsubi[0]; + a = ((u_int64_t)buffer->a[2] << 32 | (u_int64_t)buffer->a[1] << 16 + | buffer->a[0]); - result = X * a + buffer->c; + result = X * a + buffer->c; - xsubi[0] = result & 0xffff; - xsubi[1] = (result >> 16) & 0xffff; - xsubi[2] = (result >> 32) & 0xffff; - }else{ - X = (u_int64_t)xsubi[2] << 16 | xsubi[1] >> 16; - a = (u_int64_t)buffer->a[2] << 16 | buffer->a[1] >> 16; - - result = X * a + buffer->c; - - xsubi[0] = result >> 16 & 0xffffffffl; - xsubi[1] = result << 16 & 0xffff0000l; - } + xsubi[0] = result & 0xffff; + xsubi[1] = (result >> 16) & 0xffff; + xsubi[2] = (result >> 32) & 0xffff; return 0; } diff --git a/Random/test/testAnonymousEngineRestore.cc b/Random/test/testAnonymousEngineRestore.cc index 1c393489bfde864f9297b3d9ccbc2d15537aba56..9d5aa49be13dcb2081e36f2471e7db3bdaa95fe9 100644 --- a/Random/test/testAnonymousEngineRestore.cc +++ b/Random/test/testAnonymousEngineRestore.cc @@ -26,6 +26,8 @@ using namespace CLHEP; +template <class E1, class E2> int anonymousRestoreStatics(); + // Absolutely Safe Equals Without Registers Screwing Us Up bool equals01(const std::vector<double> &ab) { @@ -214,7 +216,7 @@ int anonymousRestoreStatics1() { stat |= 131072; } } - if (stat & 131072 == 0) { + if ( (stat & 131072) == 0) { output << "All captured output agrees with earlier values\n"; } return stat; @@ -274,7 +276,7 @@ int anonymousRestoreStatics() { stat |= 524288; } } - if (stat & 524288 == 0) { + if ((stat & 524288) == 0) { output << "All captured output agrees with earlier values\n"; } double k1 = e2->flat(); diff --git a/Random/test/testRandDists.cc b/Random/test/testRandDists.cc index 675c1699658c9d34275207b656353b7ad7e63a7e..3d999dbbbcc75d85078c4aa5fab5dc59c6c5bc8c 100755 --- a/Random/test/testRandDists.cc +++ b/Random/test/testRandDists.cc @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: testRandDists.cc,v 1.5.4.2 2005/04/15 16:32:53 garren Exp $ +// $Id: testRandDists.cc,v 1.5.4.3 2008/07/17 19:00:45 garren Exp $ // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- @@ -203,8 +203,9 @@ bool gaussianTest ( HepRandom & dist, double mu, ncounts[ciu] = 0; } - double x; - double u; + // hack so that gcc 4.3 puts x and u into memory instead of a register + volatile double x; + volatile double u; int ipr = nNumbers / 10 + 1; for (int ifire = 0; ifire < nNumbers; ifire++) { x = dist(); // We avoid fire() because that is not virtual diff --git a/Random/test/testRandom.cc b/Random/test/testRandom.cc index c9dd17cb5ac1bc6be35b491a55ab95e0fe88fbbb..145c0d17cb424a4aedc67d7bcf0093cc22f7aa62 100755 --- a/Random/test/testRandom.cc +++ b/Random/test/testRandom.cc @@ -1,8 +1,9 @@ // -*- C++ -*- -// $Id: testRandom.cc,v 1.1 2003/07/17 19:20:29 garren Exp $ +// $Id: testRandom.cc,v 1.1.4.1 2008/07/17 19:00:45 garren Exp $ // ---------------------------------------------------------------------- #include "CLHEP/Random/Randomize.h" #include <iostream> +#include <cstdlib> // for exit() using std::cout; using std::endl; diff --git a/Random/test/testStaticStreamSave.cc b/Random/test/testStaticStreamSave.cc index 5da0e2bcdbe6a2321d09fdaa5b0aa75186904a68..d366727e78dea5086135c39318125a84b89d9072 100644 --- a/Random/test/testStaticStreamSave.cc +++ b/Random/test/testStaticStreamSave.cc @@ -360,7 +360,7 @@ int main() { stat |= 131072; } } - if (stat & 131072 == 0) { + if ((stat & 131072) == 0) { output << "All captured output agrees with earlier values\n"; } #endif