HPUX Invalid Address Alignment when assigning double, casting to same type works?

J

Jay Hamilton

Hello,

I am running into an invalid address alignment error on an HPUX box
when I attempt to lookup a value in a STL map. The argument being
passed in is a double, which is accessed from a structure; the map's
key is also a double. The issue seemed to be occuring in the map's
default comparison function so I implemented my own comparison
operator, but then the error continued happening in my new fxn.

Strangely, casting the double I pass in to a double seems to correct
the issue. This seems like a bad way to correct the problem, has
anyone dealt with a similar issue? I can get to the line of code in
the debugger that raises the error in the operator() fxn, and the left
and right variables both have correct values when I examine them.


struct MyLess : public binary_function<double, double, bool>
{
bool operator()(const double& left, const double& right) const
{
double dLeft(left);
double dRight(right); // Raises the error. right is valid tho-
return (dLeft < dRight);
}
};


typedef std::map<double, MyStruct*, MyLess> MyMap;

...

map.find(pAnotherStruct->dMyDouble); // Casting to a double here
corrects the error.
//Why?
 
V

Victor Bazarov

Jay said:
I am running into an invalid address alignment error on an HPUX box
when I attempt to lookup a value in a STL map. The argument being
passed in is a double, which is accessed from a structure; the map's
key is also a double. The issue seemed to be occuring in the map's
default comparison function so I implemented my own comparison
operator, but then the error continued happening in my new fxn.

Strangely, casting the double I pass in to a double seems to correct
the issue. This seems like a bad way to correct the problem, has
anyone dealt with a similar issue? I can get to the line of code in
the debugger that raises the error in the operator() fxn, and the left
and right variables both have correct values when I examine them.


struct MyLess : public binary_function<double, double, bool>
{
bool operator()(const double& left, const double& right) const
{
double dLeft(left);
double dRight(right); // Raises the error. right is valid tho-
return (dLeft < dRight);
}
};


typedef std::map<double, MyStruct*, MyLess> MyMap;

...

map.find(pAnotherStruct->dMyDouble); // Casting to a double here
corrects the error.
//Why?

I believe this is covered in the FAQ 5.8.

V
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,954
Messages
2,570,116
Members
46,704
Latest member
BernadineF

Latest Threads

Top