0

I'm relatively new to C++, so go easy. When assert gets something that evaluates to false, I get this in the terminal:

test: test.cpp:185: void test(): Assertion `actual == testing` failed.
Aborted

How does assert get the input as a string? Wouldn't assert just "see" true or false?

sudo rm -rf slash
  • 1,156
  • 2
  • 16
  • 27
  • 3
    possible duplicate of [How to use Macro argument as string literal?](http://stackoverflow.com/questions/10507264/how-to-use-macro-argument-as-string-literal) – Daniel A. White Sep 23 '15 at 01:01
  • What does your assert statement look like, add the code to the question -- the answer lies in that information – Soren Sep 23 '15 at 01:01
  • I'd delete it since this question doesn't add much more to what is already answered. – Michael Petch Sep 23 '15 at 01:03

1 Answers1

1

You can implement your own version of assert as a macro. This may or may not be how your compiler implements it.

Since #something will expand to a stringified version of it, you can do:

#define str(s) #s
#define assert(x) if(!x) {print(".... Assertion `" str(s) "` failed.")

See GCC docs for more information.

viraptor
  • 33,322
  • 10
  • 107
  • 191