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

Discussion in 'C++' started by Jay Hamilton, Aug 11, 2006.

  1. Jay Hamilton

    Jay Hamilton Guest

    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?
    Jay Hamilton, Aug 11, 2006
    #1
    1. Advertising

  2. Jay Hamilton wrote:
    > 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
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Aug 11, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Artie Gold
    Replies:
    0
    Views:
    506
    Artie Gold
    Aug 21, 2003
  2. Ron Natalie
    Replies:
    3
    Views:
    5,823
    Artie Gold
    Aug 21, 2003
  3. Mike Wahler
    Replies:
    2
    Views:
    493
    Ron Natalie
    Aug 22, 2003
  4. Sydex
    Replies:
    12
    Views:
    6,475
    Victor Bazarov
    Feb 17, 2005
  5. Replies:
    2
    Views:
    424
Loading...

Share This Page