Skip to content

Instantly share code, notes, and snippets.

@illescasDaniel
Last active November 30, 2016 12:35
Show Gist options
  • Select an option

  • Save illescasDaniel/6f1a5c2979162b4a7d416debe2f53a0b to your computer and use it in GitHub Desktop.

Select an option

Save illescasDaniel/6f1a5c2979162b4a7d416debe2f53a0b to your computer and use it in GitHub Desktop.
Custom assertion [C++]
#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