Sujet : Re: dbg_break macro
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.cDate : 06. Jun 2024, 17:17:27
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240606080535.391@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-06-05, Thiago Adams <
thiago.adams@gmail.com> wrote:
Checking the usages of assert(0) in my code it is used to create a
breakpoint in unusual situations. Sample
>
if (condition) {
>
}
else {
assert(0); //unexpected
return 1;
}
It's just too much boilerplate, and in the end you you get a "assertion
0 failed in foo.c:42".
Prefer:
assert (condition);
The "return 1" is only reachable if assertions are turned
off with NDEBUG. If you need that, make your own assert macro.
I am thinking in replacing all my assert(0) for this macro.
>
#define dbg_break(message) assert(! "dbg_break" message );
>
if (condition) {
>
}
else {
dbg_break("unexpected");
return 1;
}
The message "unexpected" is still unrelated to condition,
and you have all the boiler-plate. It could all be packaged
into some kind of:
dbg_break_ret(condition, 1);
if the condition is false, there is a debug break, but in
some mode of compilation, the alternative return is
executed.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca