I have some useful code in constructor or class Valuable. I want be sure it's executed before submain. How can I guarantee that it's not optimized out?
int main()
{
// Dear compiler, please don't optimize ctor call out!
Valuable var;
return submain();
}
Is local variable enough? Do I need to use static:
static Valuable *v = new Valuable();
delete v;
v = NULL;
Can I shorten previous to one liner:
delete new Valuable();
If your constructor or destructor has observable behavior, the compiler is not allowed to optimize it out. So there's no need to do anything tricky.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With