Opened 16 years ago
Closed 16 years ago
#261 closed enhancement (fixed)
Implement yat_assert properly
Reported by: | Jari Häkkinen | Owned by: | Jari Häkkinen |
---|---|---|---|
Priority: | major | Milestone: | yat 0.4 |
Component: | test | Version: | trunk |
Keywords: | Cc: |
Description
The vanilla version provided by Peter do not work on Mac. Some more thoughts are needed to get an operating system independent function.
changeset:921 simply removes the yat_assert macro. This is not safe. Temporary fix to get a clean compile.
Change History (9)
comment:1 follow-up: 3 Changed 16 years ago by
comment:2 Changed 16 years ago by
Jari knows that so let me try to rephrase what he said:
In the inactive case we are now replacing yat_assert with nothing at the preprocessor level and this is not particularly safe. One would like to have the same void statement that normal assert has on each system.
I guess surrounding the inactive case with something like
#define NDEBUG #define yat_assert(expr) (assert(expr)) #undef NDEBUG
in a way that sets NDEBUG to its original value at the end will not work with the one pass preprocessor? If it does work it would be a nice way of getting the inactive implementation to be the same as for assert on each system.
Alternatively, is
#define yat_assert(expr) (void(0))
good enough?
Finally, the normal assert can be included multiple times, We have guards against that in yat_assert. Should we allow different yat_assert levels in different parts of a program? From cassert:
// No include guards on this header...
and from assert.h
/* * Unlike other ANSI header files, <assert.h> may usefully be included * multiple times, with and without NDEBUG defined. */
comment:3 Changed 16 years ago by
Well, the active player did not become active in my system. The inactive statement was not a void statement on my Mac.
Replying to peter:
But the active player here is
# define yat_assert(expr) (assert(expr))
What you removed was just a void statement that that I stole from my std implementation.
comment:5 Changed 16 years ago by
How are macro and namespaces working together?
If we place the macro in a namespace it must work for both
theplu::yat::utility::yat_assert(false);
and
namespace theplu{ yat::utility::yat_assert(false); }
et cetera
comment:6 Changed 16 years ago by
Should yat_assert be a macro at all? Avoid macros is a rule we learn. Is there a possibility to make it a function of some sort that goes away when the yat assert should not be active.
comment:7 Changed 16 years ago by
You are right. Bjarne suggests an Assert function that throws an exception. His reasoning is that one then can leave some assertions in production code when that is desirable.
see section 24.3.7.2 (3rd ed)
comment:9 Changed 16 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
But the active player here is
# define yat_assert(expr) (assert(expr))
What you removed was just a void statement that that I stole from my std implementation.