Jump to content
  • Advertisement
Sign in to follow this  
King of Men

Moving a variable declaration affects unit test...

This topic is 1338 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

Maybe you use one member in the constructor for initializing the other and as the construction order depends on their declaration order it may change the outcome.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!