mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Stephen Satchell <satch@fluent-access.com>
To: Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] gcc-3.0 warnings
Date: Fri, 23 Mar 2001 17:16:26 -0800	[thread overview]
Message-ID: <4.3.2.7.2.20010323170728.00b31100@mail.fluent-access.com> (raw)
In-Reply-To: <20010323163129.B2534@kochanski.internal.splhi.com>
In-Reply-To: <20010323235909.C3098@werewolf.able.es> <20010323162956.A27066@ganymede.isdn.uiuc.edu> <Pine.LNX.4.31.0103231433380.766-100000@penguin.transmeta.com> <20010323235909.C3098@werewolf.able.es>

At 04:31 PM 3/23/01 -0800, you wrote:
>This has nothing to do with fastpathing and object code optimization. C
>doesn't have exception handling, so you either have to remember to undo
>allocations etc.  in failure cases all through the code, or you stick your
>undo code at the end of the function and have all failure cases jump to the
>relevant label.  It's not pretty, but it's much less error-prone e.g.

Really?  I have a "cleanup" function that can be called during failure 
cases (and success cases -- but you didn't mention that) so that the cost 
is very low and I don't have to code ANY labels.

But then again, I'm a double-pipe abuser, in that I tend to code "atomic" 
sequences as

if ((a) || (b) || (c) || (d) || (e) || (f) || (g) || ... ) { something 
failed}  else {it all worked!}

and make sure that the failure value is non-zero for each a, b, c, d, and 
so forth.

I remember looking at the generated code from one compiler for x86 and 
seeing a series of short jumps to short jumps to short jumps... to the 
failure case, which in that particular sequence saved about 100 bytes.  I 
haven't looked at GCC output yet to see what it does, but working in a 
32-bit system instead of a 16-bit system I tend to care a little less about 
"efficiency".

Does that mean that I avoid "goto"?  No. Like every other construct in the 
C language, there is a valid and appropriate use for every single 
thing.  The key is recognizing when the goto is appropriate.

Another thing you will see in my code is resource pointers being 
initialized to zero on entry, set to non-zero values as resources are 
allocated, and then conditionally released based on whether the value is 
zero or non-zero.  It makes recovery from malloc failures easier, for one 
thing.

Satch. the || Abuser.


  parent reply	other threads:[~2001-03-24  1:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-23  0:11 J . A . Magallon
2001-03-23  0:28 ` Alan Cox
2001-03-23  0:38   ` J . A . Magallon
2001-03-23  9:29     ` Tim Waugh
2001-03-23 23:56     ` Ingo Oeser
2001-03-23 22:29   ` Bill Wendling
2001-03-23 22:34     ` Linus Torvalds
2001-03-23 22:59       ` J . A . Magallon
2001-03-24  0:31         ` Tim Wright
2001-03-24  0:42         ` Andrew Morton
2001-03-24  0:55           ` J . A . Magallon
2001-03-24 21:51             ` Tim Waugh
2001-03-24  5:30         ` Ion Badulescu
2001-03-24  1:16       ` Stephen Satchell [this message]
2001-03-26 14:25         ` Tim Wright
2001-03-23 17:12 ` Horst von Brand

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4.3.2.7.2.20010323170728.00b31100@mail.fluent-access.com \
    --to=satch@fluent-access.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®