Click to See Complete Forum and Search --> : A question about the precompiled directive ASSERT


George2
January 22nd, 2003, 03:18 AM
Hi, everyone!

Please look at the following code,

--------
#if ASSERT
sprintf (s, "_Assert: %s, %d",__FILE__, __LINE__ );
#else
//...
#endif
--------

I want to know where is the precompiled directive ASSERT defined?
Is it compiler system defined variable? What is the meaning and
function of it?


Thanks in advance,
George

PaulWendt
January 22nd, 2003, 06:29 AM
It depends on your compiler; it's my understanding that ASSERT
isn't part of the C standard so using it might be nonportable
[as opposed to assert(), which should be portable]. Anyway,
in my compiler, ASSERT is #define'd in crtdbg.h, afx.h, and I'm sure
it's #define'd other ways in other places as well. Do a grep or
similar search through your compiler's header files and find out
for yourself where it'll be #define'd on your system.

--Paul

George2
January 22nd, 2003, 07:29 AM
Thanks!

George
Originally posted by PaulWendt
It depends on your compiler; it's my understanding that ASSERT
isn't part of the C standard so using it might be nonportable
[as opposed to assert(), which should be portable]. Anyway,
in my compiler, ASSERT is #define'd in crtdbg.h, afx.h, and I'm sure
it's #define'd other ways in other places as well. Do a grep or
similar search through your compiler's header files and find out
for yourself where it'll be #define'd on your system.

--Paul

Dmitry Zemskov
January 23rd, 2003, 10:28 PM
Moreover, ASSERT is a non-standard Microsoft MFC substitution for standard C assert macro. Nota bene, ASSERT is in effect only when the MFC macro _DEBUG defined, opposed to assert, which depends on the standard NDEBUG macro.