views:

162

answers:

1

Exactly what the title says. I'm using MSVC++ 2008 express, and my class constructor is never executed when compiled in release mode. It DOES work in debug mode.

I am doing something like:

ClassTest test;
test.DoIt();

Breakpoints on DoIt(); trigger, but breakpoints on ClassTest::ClassTest(); do not.

+5  A: 

Just a thought - it could be compiler optimisation in Release mode that is preventing the breakpoint being hit. This could happen if the constructor isn't doing anything (i.e. it's a no-op). Try adding a few simple statements to the constructor, e.g.

  1. Declare a local variable
  2. Initialise the variable
  3. Use it in some way (e.g. print it out)

Then add a breakpoint on step (3) above, and see if that breakpoint is hit.

You can see all sorts of weird debugging issues with the way breakpoints are hit in Release mode, because of the optimisations which are made.

LeopardSkinPillBoxHat
This is correct, but it if you declare and initialize an int, and then don't use it, it still may be optimized out, and result in the breakpoint not firing. You want to include a statement that has external side effects so the compiler cannot optimize it out.
Matt Green
Turns out I'm a dumb-ass, the constructor WAS being executed. I accidentally supplied wsa.wVersion as first parameter to WSAStartup, instead of using MAKEWORD which for some reason appears to work in debug mode.
Thanks Matt - that is a good point. Initialising a variable was the first thing which came to mind just to test the theory, but actually using the variable would be very important as well. I'll update the answer.
LeopardSkinPillBoxHat