Sign in to follow this  
King of Men

Moving a variable declaration affects unit test...

Recommended Posts

So if I declare my class this way:

private:
  vector<ContractInfo*> obligations;
  map<EconActor*, double> borrowers;
  double discountRate;

then my unit tests fail. But if I do it this way:

private:
  double discountRate;
  vector<ContractInfo*> obligations;
  map<EconActor*, double> borrowers;

they pass. My heart fills with unbounded joy at the thought of tracking this one down...

 

I suspect I have a destructor somewhere that I ought to have declared virtual, but didn't. Any better guesses?

Share this post


Link to post
Share on other sites

Turns out I was looking up an un-initialised variable, interpreting it as double, and consistently getting NaN in one case and some small but numerical value in the other. Not sure why the variable location should so consistently flip me between NaN and number, though. Unless perhaps it is the struct layout that does it; the value in question comes from dereferencing the end of that map.

Share this post


Link to post
Share on other sites

You may have changed the size of the class due to additional (or few) pad bytes inserted by the compiler to correctly align the members. Check sizeof(the type) before and after, or use /d1reportSingleClass layout in VS.

Share this post


Link to post
Share on other sites

Turns out I was looking up an un-initialised variable, interpreting it as double, and consistently getting NaN in one case and some small but numerical value in the other. Not sure why the variable location should so consistently flip me between NaN and number, though

 

Probably just coincidence...

Even though the value in this case is "undefined", in practice, it can be deterministic.

It probably was initialized as part of another object, that then went out of scope, and the memory then reused for this object.

Edited by Olof Hedman

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this