assert() with message

Alexandru picture Alexandru · May 3, 2011 · Viewed 38.3k times · Source

I saw somewhere assert used with a message in the following way:

assert(("message", condition));

This seems to work great, except that gcc throws the following warning:

warning: left-hand operand of comma expression has no effect

How can I stop the warning?

Answer

pmg picture pmg · May 3, 2011

Use -Wno-unused-value to stop the warning; (the option -Wall includes -Wunused-value).

I think even better is to use another method, like

assert(condition && "message");