Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASSERT vs. ATLASSERT vs. assert

Tags:

c++

assert

mfc

I am refactoring some MFC code that is littered with ASSERT statements, and in preparation for a future Linux port I want to replace them with the standard assert. Are there any significant differences between the two implementations that people know of that could bite me on the backside?

Similarly, I have also come across some code that uses ATLASSERT which I would also like to replace.

like image 482
Rob Avatar asked Nov 06 '08 22:11

Rob


People also ask

What is the difference between assert () and Static_assert ()?

static_assert is meant to make compilation fail with the specified message, while traditional assert is meant to end the execution of your program.

What is assert in MFC?

An assertion statement specifies a condition that you expect to be true at a point in your program. If that condition is not true, the assertion fails, execution of your program is interrupted, and the Assertion Failed dialog box appears.

Does assert throw an exception C++?

Exceptions versus assertions Use assert statements to test for conditions during development that should never be true if all your code is correct. There's no point in handling such an error by using an exception, because the error indicates that something in the code has to be fixed.

What is the function of assert?

The assert() function tests the condition parameter. If it is false, it prints a message to standard error, using the string parameter to describe the failed condition. It then sets the variable _assert_exit to one and executes the exit statement.


3 Answers

No. The MFC version just includes an easy to debug break point.

like image 61
KJAWolf Avatar answered Oct 08 '22 23:10

KJAWolf


Replace them with your own assertion macro. That's how you get the most benefit out of it (logging, stack trace, etc.)

like image 45
Carl Seleborg Avatar answered Oct 08 '22 23:10

Carl Seleborg


I would recommend either using your own macro, or #define's for the linux compilation. There's no compelling reason to give up any extra helpfulness on the Windows side (eg: built-in breakpoint), and no compelling reason to change a lot of code when some simple compatibility #define's will suffice.

like image 41
Nick Avatar answered Oct 09 '22 01:10

Nick