Skip to content

Instantly share code, notes, and snippets.

@jonathan-beard
Last active January 4, 2016 19:51
Show Gist options
  • Save jonathan-beard/25c74f8e318688243d30 to your computer and use it in GitHub Desktop.
Save jonathan-beard/25c74f8e318688243d30 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <cstdlib>
/** try with -O0 then -O3 **/
struct foo
{
/**
* remember, this should be undetermined....
* never leave a class var like this
*/
bool x;
};
int
main( int argc, char **argv )
{
foo f;
/**
* compiler seems to optimize this to f.x always true
* unless we add default initialization explicitely for
* x or else to set, but you shouldn't rely on this...
* in fact, NEVER rely on this.
*/
if( argc == 2 )
{
f.x = true;
}
std::cout << std::boolalpha << f.x << "\n";
return( EXIT_SUCCESS );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment