0

I have a C++ program which works well when I compile with no additional options. However, whenever I use cmake -DCMAKE_BUILD_TYPE=Release there is a very specific part of the code which stops working.

Concretely, I have an interface for a Boost Fibonacci Heap. I am calling this function:

narrow_band_.push(myObject);

And this function does the following:

inline void myHeap::push (myStruct & c) {
    handles_[c.getIndex()] = heap_.push(c);
}

where heap_ is:

boost::heap::fibonacci_heap<myStruct, boost::heap::compare<compare_func>> heap_;

For some reason the heap_size is not being modified, therefore the rest of the code does not work because the next step is to extract the minimum from the heap and it is always empty.

In Debug mode it works ok. Thank you for your help.

EDIT - Additional info I have also found this problem: I have a set of code which do simple math operations. In Release mode the results are incorrect. If I just do cout of a couple of variables to check their values, the result changes, which is still incorrect but quite strange.

Javi
  • 3,440
  • 5
  • 29
  • 43
  • Make sure that you never put a function call with side effects inside an assert(). I have wasted quite a bit of time on that one. – Kristian Duske Feb 13 '14 at 10:34
  • I am not using assert(), actually I am not using any advanced or error checking feature. But thanks for the info. – Javi Feb 13 '14 at 10:38
  • 1
    This should be related: http://stackoverflow.com/questions/312312/what-are-some-reasons-a-release-build-would-run-differently-than-a-debug-build. Maybe it could be of some help. – Andrea Feb 13 '14 at 10:46
  • From that proposed post I get the following: if compiling with RelWithDebInf the error disappears (which is my case), then it most probably is a timing or initialization problem. However, since I'm running in a single thread program, should I care about timing? actually I found that other mathematical operations do not give the expected result. – Javi Feb 13 '14 at 11:06

1 Answers1

0

I solved the problem. It was funny but in this case it was not initialization/timing issues common in the Release mode. It was that the return statement was missing in a couple of functions. In debug mode the output was perfect but in the release mode that failed. I had warnings deactivated, that is why I did not see it before.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Javi
  • 3,440
  • 5
  • 29
  • 43
  • 2
    Which is why you should not deactivate warnings :-) The number of times I debug someones code, to find the issue was already highlighted by a warning.... – mjs Feb 27 '14 at 13:02
  • Actually warning were not deactivated... there were just not activated which is not the case because I never chose to deactivate them (I would never choose that!) ^^ – Javi Feb 27 '14 at 15:32