// assert() with printf() style messaging example by gbmhunter for www.mbedded.ninja
// Designed as an example of assert() for embedded systems.
// See http://w...content-available-to-author-only...d.ninja/programming/languages/c/assertions-assert
#include <cassert>
#include <cstdio>
#define LOG_ERROR(M, ...) fprintf(stderr, "[ERROR] (%s:%d) " M "\r\n", __FILE__, __LINE__, ##__VA_ARGS__)
#define assertf(A, M, ...) if(!(A)) { LOG_ERROR(M, ##__VA_ARGS__); assert(A); }
int main() {
int x = 6;
assertf(x == 7, "x must equal 7. x = %i.", x);
}
Ly8gYXNzZXJ0KCkgd2l0aCBwcmludGYoKSBzdHlsZSBtZXNzYWdpbmcgZXhhbXBsZSBieSBnYm1odW50ZXIgZm9yIHd3dy5tYmVkZGVkLm5pbmphCi8vIERlc2lnbmVkIGFzIGFuIGV4YW1wbGUgb2YgYXNzZXJ0KCkgZm9yIGVtYmVkZGVkIHN5c3RlbXMuCi8vIFNlZSBodHRwOi8vdy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uZC5uaW5qYS9wcm9ncmFtbWluZy9sYW5ndWFnZXMvYy9hc3NlcnRpb25zLWFzc2VydAojaW5jbHVkZSA8Y2Fzc2VydD4KI2luY2x1ZGUgPGNzdGRpbz4KCiNkZWZpbmUgTE9HX0VSUk9SKE0sIC4uLikgZnByaW50ZihzdGRlcnIsICJbRVJST1JdICglczolZCkgIiBNICJcclxuIiwgX19GSUxFX18sIF9fTElORV9fLCAjI19fVkFfQVJHU19fKQojZGVmaW5lIGFzc2VydGYoQSwgTSwgLi4uKSBpZighKEEpKSB7IExPR19FUlJPUihNLCAjI19fVkFfQVJHU19fKTsgYXNzZXJ0KEEpOyB9CgppbnQgbWFpbigpIHsgICAgCiAgICBpbnQgeCA9IDY7ICAgIAogICAgYXNzZXJ0Zih4ID09IDcsICJ4IG11c3QgZXF1YWwgNy4geCA9ICVpLiIsIHgpOyAgICAKfQo=