Re: So You Think You Can Const?

Liste des GroupesRevenir à cl c 
Sujet : Re: So You Think You Can Const?
De : julio (at) *nospam* diegidio.name (Julio Di Egidio)
Groupes : comp.lang.c
Date : 15. Jan 2025, 13:56:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vm8b9d$2uq20$5@dont-email.me>
References : 1 2 3 4 5 6 7 8 9
User-Agent : Mozilla Thunderbird
On 09/01/2025 10:35, David Brown wrote:
On 09/01/2025 05:24, Kaz Kylheku wrote:
On 2025-01-09, Ben Bacarisse <ben@bsb.me.uk> wrote:
Julio Di Egidio <julio@diegidio.name> writes:
>
static AvlTree_t const *AvlTree_node(
     void const *pk, AvlTree_t const *pL, AvlTree_t const *pR
) {
     AvlTree_t *pT;
>
     pT = malloc(sizeof(AvlTree_t));
>
     if (!pT) {
         return NULL;
     }
>
     pT->pk = pk;
     pT->pL = pL;
     pT->pR = pR;
>
     return pT;
}
>
Just on a side issue, I prefer to make tests like this positive so I'd
write:
>
  static AvlTree_t const *AvlTree_node(
      void const *pk, AvlTree_t const *pL, AvlTree_t const *pR
  ) {
      AvlTree_t *pT = malloc(*pT);
      if (pT) {
          pT->pk = pk;
          pT->pL = pL;
          pT->pR = pR;
      }
      return pT;
  }
>
More generally:
>
    foo_handle *foo = foo_create();
    bar_handle *bar = foo ? bar_create(foo) : 0; // doesn't like null
    xyzzy_handle *xyz = xyzzy_create(42, bar, arg);
    container *con = malloc(sizeof *con);
>
    if (foo && bar && xyz && con) {
      // happy case: we have all three resources
>
      con->foo = foo;
      con->bar = bar;
      con->xyz = xyz;
>
      return con;
    }
>
    xyzzy_destroy(xyz);
    xyzzy_destroy(bar);
    if (foo)
       xyzzy_destroy(foo); // stupidly doesn't like null
>
    return 0;
>
I'm not going to "make a case" for this (though I will if you want!) --
I just think it helps to see lots of different styles.
>
I might just have made the case. When more resources need to be
acquired that might fail, it consolidates the happy case under one
conjunctive test, and consolidates the cleanup in the unhappy case.
Effectively it's almost if we have only two cases.
>
A minor disadvantage is that in the unhappy flow, we may allocate
resources past the point where it is obvious they are not going to be
needed: if foo_create() failed, we are pointlessly calling
xyzzy_create() and malloc for the container. It's possible that these
succeed, and we are just going to turn around and free them.
>
 How about taking the idea slightly further and making the later allocations conditional too?
     foo_handle *foo = foo_create();
    bar_handle *bar = foo ? bar_create(foo) : 0; // doesn't like null
    xyzzy_handle *xyz = bar ? xyzzy_create(42, bar, arg) : 0;
    container *con = xyz ? malloc(sizeof *con) : 0;
     if (con) {
      // happy case: we have all three resources
     ...
 If you are going to use that style (and I not arguing for or against it), go all in!
 
It's a form of consolidated error checking, like when we make
several system calls and check them for errors as a batch;
e.g. call fprintf several times and check for disk full (etc)
just once.
HOW about you and that piece of nazi-retarded shit rather go fuck yourself somewhere else?  Eh??  Yeah, that would be it: I am having a great idea: YOU GO fuck yourself out of cpomp.lang.cv !! I am a fucking genius...
-Julio

Date Sujet#  Auteur
7 Jan 25 * So You Think You Can Const?174Julio Di Egidio
7 Jan 25 +* Re: So You Think You Can Const?80Kaz Kylheku
8 Jan 25 i`* Re: So You Think You Can Const?79Julio Di Egidio
8 Jan 25 i +- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i `* Re: So You Think You Can Const?77Ben Bacarisse
8 Jan 25 i  +- Re: So You Think You Can Const?1David Brown
8 Jan 25 i  +* Re: So You Think You Can Const?72Julio Di Egidio
8 Jan 25 i  i+* Re: So You Think You Can Const?64Julio Di Egidio
8 Jan 25 i  ii+- Re: So You Think You Can Const?1Chris M. Thomasson
9 Jan 25 i  ii`* Re: So You Think You Can Const?62Ben Bacarisse
9 Jan 25 i  ii +* Re: So You Think You Can Const?4Kaz Kylheku
9 Jan 25 i  ii i`* Re: So You Think You Can Const?3David Brown
9 Jan 25 i  ii i +- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 i  ii i `- Re: So You Think You Can Const?1Julio Di Egidio
9 Jan 25 i  ii +* Re: So You Think You Can Const?54Julio Di Egidio
10 Jan 25 i  ii i`* Re: So You Think You Can Const?53Ben Bacarisse
10 Jan 25 i  ii i +* Re: So You Think You Can Const?46Julio Di Egidio
10 Jan 25 i  ii i i+* Re: So You Think You Can Const?44Julio Di Egidio
10 Jan 25 i  ii i ii`* Re: So You Think You Can Const?43Tim Rentsch
10 Jan 25 i  ii i ii +* Re: So You Think You Can Const?38Julio Di Egidio
10 Jan 25 i  ii i ii i+* Re: So You Think You Can Const?36Julio Di Egidio
10 Jan 25 i  ii i ii ii+- Re: So You Think You Can Const?1Julio Di Egidio
13 Jan 25 i  ii i ii ii`* Re: So You Think You Can Const?34James Kuyper
13 Jan 25 i  ii i ii ii +* Re: So You Think You Can Const?32David Brown
13 Jan 25 i  ii i ii ii i+* Re: So You Think You Can Const?29Julio Di Egidio
13 Jan 25 i  ii i ii ii ii`* Re: So You Think You Can Const?28David Brown
13 Jan 25 i  ii i ii ii ii +* Re: So You Think You Can Const?26Julio Di Egidio
13 Jan 25 i  ii i ii ii ii i`* Re: So You Think You Can Const?25David Brown
14 Jan 25 i  ii i ii ii ii i +* Re: So You Think You Can Const?22Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i i+* Re: So You Think You Can Const?16bart
14 Jan 25 i  ii i ii ii ii i ii`* Re: So You Think You Can Const?15David Brown
14 Jan 25 i  ii i ii ii ii i ii +* Re: So You Think You Can Const?7James Kuyper
14 Jan 25 i  ii i ii ii ii i ii i+- Re: So You Think You Can Const?1Dan Cross
14 Jan 25 i  ii i ii ii ii i ii i`* Re: So You Think You Can Const?5David Brown
14 Jan 25 i  ii i ii ii ii i ii i `* Re: So You Think You Can Const?4James Kuyper
15 Jan 25 i  ii i ii ii ii i ii i  `* Re: So You Think You Can Const?3James Kuyper
15 Jan 25 i  ii i ii ii ii i ii i   `* Re: So You Think You Can Const?2David Brown
15 Jan 25 i  ii i ii ii ii i ii i    `- Re: So You Think You Can Const?1Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i ii +* Re: So You Think You Can Const?2Chris M. Thomasson
14 Jan 25 i  ii i ii ii ii i ii i`- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 i  ii i ii ii ii i ii `* Re: So You Think You Can Const?5Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii  +- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii  `* Re: So You Think You Can Const?3Kaz Kylheku
15 Jan 25 i  ii i ii ii ii i ii   `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i ii    `- Re: So You Think You Can Const?1Julio Di Egidio
14 Jan 25 i  ii i ii ii ii i i+- Re: So You Think You Can Const?1James Kuyper
14 Jan 25 i  ii i ii ii ii i i`* Re: So You Think You Can Const?4Keith Thompson
15 Jan 25 i  ii i ii ii ii i i `* Re: So You Think You Can Const?3Kenny McCormack
15 Jan 25 i  ii i ii ii ii i i  `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i i   `- Re: So You Think You Can Const?1Kaz Kylheku
15 Jan 25 i  ii i ii ii ii i `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii ii i  `- Re: So You Think You Can Const?1Kaz Kylheku
15 Jan 25 i  ii i ii ii ii `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii i`* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii i ii ii i `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii i ii ii `- Re: So You Think You Can Const?1Julio Di Egidio
13 Jan 25 i  ii i ii i`- Re: So You Think You Can Const?1Tim Rentsch
15 Jan 25 i  ii i ii `* Re: So You Think You Can Const?4Julio Di Egidio
18 Jan 25 i  ii i ii  `* Re: So You Think You Can Const?3Tim Rentsch
19 Jan 25 i  ii i ii   `* Re: So You Think You Can Const?2Julio Di Egidio
20 Jan 25 i  ii i ii    `- Re: So You Think You Can Const?1Chris M. Thomasson
10 Jan 25 i  ii i i`- Re: So You Think You Can Const?1Ben Bacarisse
12 Jan 25 i  ii i +* Re: So You Think You Can Const?5Waldek Hebisch
12 Jan 25 i  ii i i+* Re: So You Think You Can Const?3Julio Di Egidio
13 Jan 25 i  ii i ii`* Re: So You Think You Can Const?2David Brown
13 Jan 25 i  ii i ii `- Re: So You Think You Can Const?1James Kuyper
13 Jan 25 i  ii i i`- Re: So You Think You Can Const?1David Brown
15 Jan 25 i  ii i `- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii +- Re: So You Think You Can Const?1Julio Di Egidio
15 Jan 25 i  ii `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 i  ii  `- Re: So You Think You Can Const?1Chris M. Thomasson
8 Jan 25 i  i+* Re: So You Think You Can Const?2James Kuyper
8 Jan 25 i  ii`- Re: So You Think You Can Const?1James Kuyper
8 Jan 25 i  i+* Re: So You Think You Can Const?2Tim Rentsch
9 Jan 25 i  ii`- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i  i+- Re: So You Think You Can Const?1Chris M. Thomasson
9 Jan 25 i  i`* Re: So You Think You Can Const?2Ben Bacarisse
9 Jan 25 i  i `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i  +* Re: So You Think You Can Const?2Tim Rentsch
9 Jan 25 i  i`- Re: So You Think You Can Const?1Ben Bacarisse
15 Jan 25 i  `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 +* Re: So You Think You Can Const?35David Brown
8 Jan 25 i+* Re: So You Think You Can Const?4Ben Bacarisse
8 Jan 25 ii`* Re: So You Think You Can Const?3David Brown
15 Jan 25 ii `* Re: So You Think You Can Const?2Julio Di Egidio
15 Jan 25 ii  `- Re: So You Think You Can Const?1Julio Di Egidio
8 Jan 25 i+* What is wrong with malloc? (Was: So You Think You Can Const?)28Julio Di Egidio
8 Jan 25 ii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)25David Brown
8 Jan 25 iii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)2Julio Di Egidio
8 Jan 25 iiii`- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1David Brown
8 Jan 25 iii+* Re: What is wrong with malloc? (Was: So You Think You Can Const?)13Phillip
8 Jan 25 iiii+- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1Tim Rentsch
8 Jan 25 iiii+* Re: What is wrong with malloc?10Keith Thompson
8 Jan 25 iiiii`* Re: What is wrong with malloc?9Phillip
8 Jan 25 iiiii `* Re: What is wrong with malloc?8Keith Thompson
9 Jan 25 iiiii  `* Re: What is wrong with malloc?7Phillip
9 Jan 25 iiiii   +* Re: What is wrong with malloc?4Keith Thompson
9 Jan 25 iiiii   i+- Re: What is wrong with malloc?1Phillip
9 Jan 25 iiiii   i`* Re: What is wrong with malloc?2Michael S
9 Jan 25 iiiii   i `- Re: What is wrong with malloc?1Phillip
9 Jan 25 iiiii   `* Re: What is wrong with malloc?2David Brown
9 Jan 25 iiii`- Re: What is wrong with malloc? (Was: So You Think You Can Const?)1David Brown
8 Jan 25 iii+* Re: What is wrong with malloc?3Keith Thompson
9 Jan 25 iii`* Re: What is wrong with malloc? (Was: So You Think You Can Const?)6Julio Di Egidio
8 Jan 25 ii`* Re: What is wrong with malloc? (Was: So You Think You Can Const?)2James Kuyper
8 Jan 25 i+- Re: So You Think You Can Const?1Kaz Kylheku
8 Jan 25 i`- Re: So You Think You Can Const?1Keith Thompson
8 Jan 25 +* Re: So You Think You Can Const?51Andrey Tarasevich
8 Jan 25 +- Re: So You Think You Can Const?1Tim Rentsch
13 Jan 25 +- Re: So You Think You Can Const?1Chris M. Thomasson
15 Jan 25 +* Re: So You Think You Can Const?4Lawrence D'Oliveiro
26 Jan 25 `- Re: So You Think You Can Const?1Lawrence D'Oliveiro

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal