[Info-vax] BASIC (and Horizon)
Lawrence D'Oliveiro
ldo at nz.invalid
Wed Jan 31 16:28:01 EST 2024
On Wed, 31 Jan 2024 15:52:30 +0200, Michael S wrote:
> One option is named construct and named break.
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.
More information about the Info-vax
mailing list