mercredi 23 janvier 2019

Code being executed inside of unsatisfied (false) if statement

I've noticed some strange behaviour in my console app, where code inside an if statement seems to be having side effects, even though the condition evaluates false. Specifically, I'm using a wrapper around ncurses, and the documentation says that constructing an instance of system will initialise the display system.

The following code does not initialise the display system as one would expect . . .

const bool launchUI = false;
if(launchUI){
    cppurses::System sys;
    WidgetHead wh(dad);
    Tree::set_head(&wh);
    return sys.run();
}
return 0;

However, dropping the const qualifier on launchUI does initialise the display system, even if the value is still false! It looks like the compiler is generating code that somehow instantiates sys "just incase" it might be needed. How do I prevent this, or is my assumption even correct?

Aucun commentaire:

Enregistrer un commentaire