Last active
August 29, 2015 05:42
-
-
Save KayEss/2a7bd77f718e3c895749 to your computer and use it in GitHub Desktop.
`DEBUG` and release builds -- is it reasonable to expect the compiler to completely optimise away the `check` function on non-`DEBUG` builds, but leave the side effects of the arguments alone?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef DEBUG | |
inline void check(const auto &b) { | |
if ( !b ) std::terminate(); | |
} | |
#else | |
inline void check(const auto &) { | |
} | |
#endif | |
// Writes the data to the file. Returns true on success | |
bool save_file(std::string filename, std::string data); | |
int main() { | |
// This completely goes in release builds | |
check("Optimised out?"); | |
// save_file is called, but nothing else happens in release builds | |
check(save_file("test.txt", "Side effect left in?\n")); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment