Re: dbg_break macro

Liste des GroupesRevenir à cl c  
Sujet : Re: dbg_break macro
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.c
Date : 06. Jun 2024, 22:40:30
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v3t6ru$1jpih$2@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
On 06/06/2024 17:10, Blue-Maned_Hawk wrote:
 I feel like you would probably want to be using a debugger to set your
breakpoints, although the Clang dialect of C does have a
__builtin_debugtrap builtin subroutine.
  
C++ 26 will have breakpoint. Lot of links about how to do that.
https://en.cppreference.com/w/cpp/utility/breakpoint
But, thinking about my usage, the source line, message, etc., everything that assert has is useful. What is not useful is to pass a constant expression for something that is supposed to be a runtime check.
I remember when I thought that static_assert could just be assert because it is not hard for the compiler to know when we have a constant expression or not. If we have a constant expression, this should be just like static_assert.
assert(2 == 2); // compile-time check
If the expression is not constant, then it would be checked at runtime during debugging.
This idea fails fast, when we think assert is used with assert(0);
This code would not compile.
if (condition)
{
   ///
}
else{
   assert(0);
   return -1;
}
So, my idea with dbg_break is to reserve assert for what it does better, that is runtime checks.
Another sample
int f(int v){
  switch(v)
  {
     case 1:break;
     case 2:break;
     default:
      assert(0);
      break;
  }
}
This code does not have a plan B in case default is reached.
But this one have.
int f(int v){
  switch(v)
  {
     case 1:break;
     case 2:break;
     default:
       dbg_break("missing case ?");
      break;
  }
  return -1;
}
I think dbg_break also transmit the idea that the branch is possible while assert(0) can be confusing.

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