C++: avoid optimizing out variable -


i have useful code in constructor or class valuable. want sure it's executed before submain. how can guarantee it's not optimized out?

int main() {     // dear compiler, please don't optimize ctor call out!     valuable var;      return submain(); } 

is local variable enough? need use static:

static valuable *v = new valuable(); delete v; v = null; 

can shorten previous 1 liner:

delete new valuable(); 

if constructor or destructor has observable behavior, compiler not allowed optimize out. there's no need tricky.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -