[Info-vax] BASIC (and Horizon)

Dave Froble davef at tsoft-inc.com
Wed Jan 31 18:04:52 EST 2024


On 1/31/2024 5:08 PM, Arne Vajhøj wrote:
> On 1/31/2024 4:28 PM, Lawrence D'Oliveiro wrote:
>> I have never written a goto in C code (not production code, anyway). These
>> days, you need to do so much dynamic allocation, there is nearly always
>> some need for cleanup when exiting an inner block anyway, so you can’t
>> just jump directly somewhere else first. The overall pattern looks like
>> this:
>>
>>      MyPtr obj = NULL;
>>      do /*once*/
>>        {
>>          ... possible other stuff ...
>>          «allocate memory for obj»;
>>          if («error occurred»)
>>              break;
>>          ... possible other stuff using obj ...
>>        }
>>      while (false);
>>      free(obj);
>>
>> You can confirm, just by inspection, that there is no path out of the
>> block that does not pass through the free() call precisely once.
>
> And the difference compared to:
>
>      MyPtr obj = NULL;
>      ... possible other stuff ...
>      «allocate memory for obj»;
>      if («error occurred»)
>          goto lbl_freeobj;
>      ... possible other stuff using obj ...
>   lbl_freeobj:
>      free(obj);
>
> are?
>
> Arne
>
>

I've seen code that did all kinds of confusing things, just avoid a GoTo branch. 
  My question is, why?  If the need is a simple and rather easy to understand 
branch, why get complex, just to be "political correct", which ia also a rather 
stupid concept.

-- 
David Froble                       Tel: 724-529-0450
Dave Froble Enterprises, Inc.      E-Mail: davef at tsoft-inc.com
DFE Ultralights, Inc.
170 Grimplin Road
Vanderbilt, PA  15486



More information about the Info-vax mailing list