Re: Code guidelines

Liste des GroupesRevenir à cl c 
Sujet : Re: Code guidelines
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 01. Oct 2024, 23:39:21
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20241001134139.619@kylheku.com>
References : 1 2 3 4 5 6 7
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-10-01, Vir Campestris <vir.campestris@invalid.invalid> wrote:
On 03/09/2024 17:23, Thiago Adams wrote:
<snip>
but...maybe, is better to be a little redundant here?
I think I prefer to leave "obj->member1->member2 && " even if I know
it should not be null.
 
if (obj->member1 &&
     obj->member1->member2 &&
     obj->member1->member2->member3)
{
 
}
>
I think I'd prefer to _omit_ the check that obj->member1->member2 isn't
null.
>
If the code is running correctly that check will never trigger, and is
redundant, and will slow things slightly.

How about:

  #define vassert(x) (assert(x), 1)

  if (obj->member1 &&
      vassert(obj->member1->member2) &&
      obj->member1->member2->member3)

If NDEBUG is defined, that just reduces to 1, and is optimized
away. If NDEBUG is absent, the null pointer crash is replaced
by an assertion failure.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
3 Sep 24 * Code guidelines25Thiago Adams
3 Sep 24 +* Re: Code guidelines22David Brown
3 Sep 24 i`* Re: Code guidelines21Thiago Adams
3 Sep 24 i +* Re: Code guidelines5David Brown
3 Sep 24 i i`* Re: Code guidelines4Thiago Adams
3 Sep 24 i i +- Re: Code guidelines1David Brown
3 Sep 24 i i +- Re: Code guidelines1Chris M. Thomasson
22 Sep 24 i i `- Re: Code guidelines1Lawrence D'Oliveiro
3 Sep 24 i `* Re: Code guidelines15Thiago Adams
3 Sep 24 i  `* Re: Code guidelines14David Brown
3 Sep 24 i   `* Re: Code guidelines13Thiago Adams
3 Sep 24 i    +* Re: Code guidelines5Thiago Adams
4 Sep 24 i    i`* Re: Code guidelines4David Brown
4 Sep 24 i    i `* Re: Code guidelines3Thiago Adams
4 Sep 24 i    i  +- Re: Code guidelines1Thiago Adams
4 Sep 24 i    i  `- Re: Code guidelines1David Brown
4 Sep 24 i    +* Re: Code guidelines3David Brown
4 Sep 24 i    i`* Re: Code guidelines2Keith Thompson
4 Sep 24 i    i `- Re: Code guidelines1David Brown
4 Sep 24 i    +* Re: Code guidelines2Kaz Kylheku
4 Sep 24 i    i`- Re: Code guidelines1David Brown
1 Oct 24 i    `* Re: Code guidelines2Vir Campestris
1 Oct 24 i     `- Re: Code guidelines1Kaz Kylheku
3 Sep 24 +- Re: Code guidelines1Kaz Kylheku
3 Sep 24 `- Re: Code guidelines1Blue-Maned_Hawk

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal