tags:

views:

66

answers:

2

Hello, exists a way to add or edit the message thronw by assert. I'd like to use something like

assert(a==b,"A must be equal to B");

Then, the compiler adds line, time and so on....

It is posible?

+7  A: 

A hack I've seen around is to use the && operator. Since a pointer "is true" if it's non-null, you can do the following without altering the condition:

assert(a == b && "A is not equal to B");

Since assert shows the condition that failed, it will display your message too. If it's not enough, you can write your own myAssert function or macro that will display whatever you want.

zneak
Jaja! Fine piece of code. Really useful!! Thanks!
Killrazor
@Killrazor If it solved you problem consider marking the answer as "accepted" by clicking the checkmark next to it. :)
zneak
+1  A: 

assert is a macro/function combination. you can define your own macro/function, using __FILE__, __BASE_FILE__, __LINE__ etc, with your own function that takes a custom message

Merlyn Morgan-Graham