G
graham.macpherson
I have 2 Suse Linux PCs which I compile my code on. Until recently
they both had gcc 4.0.X on them, but I upgraded one of them to gcc
4.1.0. I have come across a very strange problem in the following code
which uses an STL map:
void Distribution::AddToDistribution (double& valueToAddToDistribution)
{
int n;
n = static_cast<int>(valueToAddToDistribution/itsBinWidth);
float keyToAddTo;
keyToAddTo = (n + 0.5)*itsBinWidth;
// std::cout << "n: " << n << ", keyToAddTo: " << keyToAddTo <<
std::endl;
std::map<float, int>::iterator addToDistributionIterator;
addToDistributionIterator = itsDistributionValues.find(keyToAddTo);
if (addToDistributionIterator == itsDistributionValues.end()) // Key
not found in map
{
itsDistributionValues[keyToAddTo] = 1;
}
else // Key present in map
{
addToDistributionIterator->second++;
}
}
On one machine with gcc version 4.0.2 20050901 (prerelease) (SUSE
Linux) (AMD 64bit) this works fine and the code goes into the "else //
Key present in map" part of the code as required. However, on the
machine with gcc version 4.1.0 (intel P4) it doesn't - the map key
isn't found - it worked fine with 4.0.X however! The strange thing is
that, if i uncomment the line:
"std::cout << "n: " << n << ", keyToAddTo: " << keyToAddTo <<
std::endl;"
to print the key value to the screen (used as a quick debug/test line),
then the code works fine and enters the "else // Key present in map"
as required.
Do you think that this is a compiler bug, or a bug in my code that the
compiler wasn't sensitive to before?
Any help gratefully received,
Graham
they both had gcc 4.0.X on them, but I upgraded one of them to gcc
4.1.0. I have come across a very strange problem in the following code
which uses an STL map:
void Distribution::AddToDistribution (double& valueToAddToDistribution)
{
int n;
n = static_cast<int>(valueToAddToDistribution/itsBinWidth);
float keyToAddTo;
keyToAddTo = (n + 0.5)*itsBinWidth;
// std::cout << "n: " << n << ", keyToAddTo: " << keyToAddTo <<
std::endl;
std::map<float, int>::iterator addToDistributionIterator;
addToDistributionIterator = itsDistributionValues.find(keyToAddTo);
if (addToDistributionIterator == itsDistributionValues.end()) // Key
not found in map
{
itsDistributionValues[keyToAddTo] = 1;
}
else // Key present in map
{
addToDistributionIterator->second++;
}
}
On one machine with gcc version 4.0.2 20050901 (prerelease) (SUSE
Linux) (AMD 64bit) this works fine and the code goes into the "else //
Key present in map" part of the code as required. However, on the
machine with gcc version 4.1.0 (intel P4) it doesn't - the map key
isn't found - it worked fine with 4.0.X however! The strange thing is
that, if i uncomment the line:
"std::cout << "n: " << n << ", keyToAddTo: " << keyToAddTo <<
std::endl;"
to print the key value to the screen (used as a quick debug/test line),
then the code works fine and enters the "else // Key present in map"
as required.
Do you think that this is a compiler bug, or a bug in my code that the
compiler wasn't sensitive to before?
Any help gratefully received,
Graham