Re: dbg_break macro

Liste des GroupesRevenir à cl c  
Sujet : Re: dbg_break macro
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 06. Jun 2024, 18: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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
5 Jun 24 * dbg_break macro6Thiago Adams
6 Jun 24 +- Re: dbg_break macro1Kaz Kylheku
6 Jun 24 `* Re: dbg_break macro4Blue-Maned_Hawk
6 Jun 24  `* Re: dbg_break macro3Thiago Adams
7 Jun 24   `* Re: dbg_break macro2David Brown
7 Jun 24    `- Re: dbg_break macro1Thiago Adams

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal