Re: [Boost-users] BOOST_ASSERT and others

Sorry, I should have checked! It should be: assert( 2 + 2 == 4 && "Adding numbers failed!" ) Maarten ----- Original Message ---- From: David Abrahams <dave@boost-consulting.com> To: boost-users@lists.boost.org Sent: Friday, December 15, 2006 5:19:05 PM Subject: Re: [Boost-users] BOOST_ASSERT and others Maarten Nieber <hallomaarten@yahoo.com> writes:
I use the trick
assert( 2 + 2 == 4 || "Adding numbers failed!" )
This will probably work for BOOST_ASSERT as well.
Are you sure about that || ? Looks to me like it would never fire. -- Dave Abrahams Boost Consulting www.boost-consulting.com _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com

Maarten Nieber wrote:
Sorry, I should have checked! It should be:
assert( 2 + 2 == 4 && "Adding numbers failed!" )
That still won't fire. The concept is flawed. You cannot use assert()s to print debug messages, because when an assert() prints a message, it also stops the program. Sebastian Redl

Sebastian Redl wrote:
Maarten Nieber wrote:
Sorry, I should have checked! It should be:
assert( 2 + 2 == 4 && "Adding numbers failed!" )
That still won't fire. The concept is flawed. You cannot use assert()s to print debug messages, because when an assert() prints a message, it also stops the program.
Actually, it will. The versions of assert that I have seen will print the complete expression that failed before they stop the program. This will include the string.

Andrew Holden wrote:
Actually, it will. The versions of assert that I have seen will print the complete expression that failed before they stop the program. This will include the string.
My mistake. I thought the post was in answer to the second issue the author presented, that of printing debug messages. Sebastian Redl

Sebastian Redl wrote: > Andrew Holden wrote: >> Actually, it will. The versions of assert that I have seen will print >> the complete expression that failed before they stop the program. This >> will include the string. >> > My mistake. I thought the post was in answer to the second issue the > author presented, that of printing debug messages. > > Sebastian Redl For the second problem, i.e. printing a debug only message , may be a simple solution is a macro like, #ifdef _DEBUG #define DEBUG_PRINT(msg) \ std::cerr << "DEBUG: " << msg << std::endl \ <<"("<<__FUNCTION__<<") "<<std::endl; #else #define DEBUG_PRINT(msg) do {} while(0); #endif But it is only too primitive one. as it lacks functionality in terms 1) not cross platform , as _DEBUG is not a standard macro. 2) it doesn't allow to evaluate an expression, only can print a string, that to only ascii. If C++ supports variable number of args in macro like C, I could have written it in terms of printf. But again, in that case type safety is important, as a statement like DEBUG_PRINT("my i is %i\n",i++) should not be allowed. -- Abir Basak, Member IEEE Software Engineer, Read Ink Technologies B. Tech, IIT Kharagpur email: abir@abirbasak.com homepage: www.abirbasak.com

As does assert( statement || !"Statement failed" ) which is 'faster' when statement == true Mike ----- Original Message ----- From: "Andrew Holden" <aholden@charteroaksystems.com> To: <boost-users@lists.boost.org> Sent: Monday, December 18, 2006 2:18 PM Subject: Re: [Boost-users] BOOST_ASSERT and others
Sebastian Redl wrote:
Maarten Nieber wrote:
Sorry, I should have checked! It should be:
assert( 2 + 2 == 4 && "Adding numbers failed!" )
That still won't fire. The concept is flawed. You cannot use assert()s to print debug messages, because when an assert() prints a message, it also stops the program.
Actually, it will. The versions of assert that I have seen will print the complete expression that failed before they stop the program. This will include the string. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (5)
-
abir basak
-
Andrew Holden
-
Maarten Nieber
-
Mike(dev)
-
Sebastian Redl