Runtime Check Failure when using Boost Date Time Library and Visual Studio 2008
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.
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.
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.
精彩评论