Commit f804e982 authored by Lynn Garren's avatar Lynn Garren
Browse files

fixes for gcc 4.3 and VC8/9

parent f27b20ea
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
==============================
......
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
==============================
......
// -*- 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 {
......
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
==============================
......
// -*- 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 );
......
// $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 {
......
// $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;
......
// -*- 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;
}
......
......@@ -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();
......
// -*- 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
......
// -*- 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;
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment