Last active
November 30, 2016 12:35
-
-
Save illescasDaniel/6f1a5c2979162b4a7d416debe2f53a0b to your computer and use it in GitHub Desktop.
Custom assertion [C++]
This file contains hidden or 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
| #include <iostream> | |
| #define xAssert(_condition, _message) if (bool(_condition) == false) { \ | |
| cerr << "Condition: " << (#_condition)<< "\nError: " << (_message) << endl; exit(1); } | |
| using namespace std; | |
| int main(int argc, char *argv[]) { | |
| xAssert(1 + 2 == 2, "wrong result"); | |
| int *p = nullptr; //new int[2]{1,2}; | |
| xAssert(p != nullptr, "pointer not initialized"); | |
| // or: xAssert(p, "pointer not initialized"); | |
| delete[] p; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment