2

I'm a first year computer science student, writing a c++ program that bubble sorts an array of randomly assigned floats and then uses a binary chop search to find the value of the last element in the array (for consistency while timing the code).

I want to time the execution of the bubble sorting and binary chop searching, but the c++ standard time library will only give me second level precision, which isn't usable as this code executes in under 1 second most of the time.

I have found Boost and I'm trying to use that as a way of getting a sub-second precision timing of the execution of code using the microsecond clock in the Boost DateTime library. The code I am using is at http://pastebin.com/U8D0s2hb. When I execute this code, I get the following error from Visual Studio 2008:

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

The culprit appears to be getting the time as a ptime object, but I have no idea why as I have never seen a runtime check failure error before.

Any help appreciated, thanks.

2 Answers2

1

This looks like a calling convention problem, but it appears it's actually a structure member alignment issue.

You have to use the default structure member alignment in your client code. In your project's properties, select Configuration Properties, C/C++, Code Generation and ensure the Structure Member Alignment options is set to Default.

See here for another question about this problem.

Community
  • 1
  • 1
Frédéric Hamidi
  • 258,201
  • 41
  • 486
  • 479
  • I have checked the Structure Member Alignment in the Project Properties Frédéric, it was set at default. I have also tried every setting under that with no improvement. I have no experience with Boost, so I'm not quite sure what to try next. – Daniel Wright Dec 12 '10 at 00:27
  • @Daniel, can you try compiling `boost` itself with the same compiler? The resulting library's ABI would be closer to your client code's and probably work better. – Frédéric Hamidi Dec 12 '10 at 07:20
0

I had the same problem with boost.thread.

I tracked the change history and I found that I added a header <windows.h> before <boost/thread.hpp>. I suspected that maybe windows.h header defined some calling conventions which would confuse boost/thread.hpp, so I put windows.h file after boost/thread.hpp, and the problem disappeared.

Hope this helps.

Guo
  • 305
  • 4
  • 13