News for hackers. Stuff that matters.
Re:A Defer Mechanism for C by quelsolaar on Monday December 14, 2020 @10:20AM (#25418507)
void * * a = NULL;

while(TRUE)

{

    a = malloc(sizeof *a);

    if(a == NULL)

        break;

    *a = malloc(1024);

    if(*a == NULL)

        break; 

    if(!do_some_other_tests(a))

        break; 

   return a;
}

/* cleanup /

if(a == NULL)

    return;
if(a != NULL)

    free(*a);

 free(a);

alt:

void * * a = NULL;

switch(TRUE)

{

    defaultt :

    a = malloc(sizeof *a);

    if(a == NULL)

        break;

    *a = malloc(1024);

    if(*a == NULL)

        break; 

    if(!do_some_other_tests(a))

        break; 

   return a;
}

/* cleanup /

if(a == NULL)

    return;
if(a != NULL)

    free(*a);

 free(a);
Re:A Defer Mechanism for C by grok22 on Monday December 14, 2020 @11:19AM (#25419277)
If the proposed implementation requires a guard clause, then it seems like it is no better than the while (TRUE) implementation above and it's not worth the support in the standard. Maybe it's a bit more structured and covers a few more use-cases, but not worth the standardization.
Re:A Defer Mechanism for C by gustedt on Tuesday December 15, 2020 @05:21PM (#25436015)
In the current proposal, the whole function body can act as a guarded block. So for simple cleanup strategies that are bound to functions, you wouldn't need this.