[bind10-dev] whether/when to use exceptions
David W. Hankins
dhankins at isc.org
Wed Oct 14 17:03:26 UTC 2009
I have one small patch (inline);
On Wed, Oct 14, 2009 at 08:44:09AM -0400, Christos Zoulas wrote:
> This is why in this case it is better to use goto's:
>
> fp = fopen("foo.txt", "w");
> if (fp == NULL)
> goto out;
>
> for (i=0; i<10; i++)
> if (fprintf(fp, "%d\n", i) < 0)
> goto out;
>
- if (fclose(fp) != 0)
- got out;
+ if (fclose(fp) != 0) {
+ /* Additional calls (e.g. to fclose(fp)) are undefined. */
+ fp = NULL;
+ goto out;
+ }
>
> return SUCCESS_CODE;
> out:
> if (fp)
> (void)fclose(fp);
> remove("foo.txt");
> return ERROR_CODE;
Alternatively you can create an 'out2' goto point after the fclose,
this is a little faster as it skips a branch, but it further
complicates what should be a linear code path.
There are some functions in BIND9 (or BIND8 libraries?) which have
nested 3-or-4 deep sections of code and goto's, where each section
had its own new constructions to de-construct, and therefore needed
its own new goto label before the previous label. I seem to recall
we got those wrong sometimes (cleanup goes in the wrong section).
--
David W. Hankins "If you don't do it right the first time,
Software Engineer you'll just have to do it again."
Internet Systems Consortium, Inc. -- Jack T. Hankins
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <https://lists.isc.org/pipermail/bind10-dev/attachments/20091014/f27d8e9d/attachment.bin>
More information about the bind10-dev
mailing list