Deutsch   English   Français   Italiano  
<20240606080535.391@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: dbg_break macro
Date: Thu, 6 Jun 2024 16:17:27 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <20240606080535.391@kylheku.com>
References: <v3ptto$vgqm$1@dont-email.me>
Injection-Date: Thu, 06 Jun 2024 18:17:27 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d10529ee17eba6921d08f9ba7a2070b1";
	logging-data="1670136"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18b8VW1zr/UGGn+9yo56+rMGMJVnoIlUq8="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:ybgfihF5+acFx2N0e/RWc8RXBWg=
Bytes: 2053

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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca