Date: Fri, 01 May 2009 22:32:23 +0200 From: Christoph Mallon <christoph.mallon@gmx.de> To: Zaphod Beeblebrox <zbeeble@gmail.com> Cc: freebsd-hackers@freebsd.org, Julian Elischer <julian@elischer.org> Subject: Re: C99: Suggestions for style(9) Message-ID: <49FB5C57.6050407@gmx.de> In-Reply-To: <5f67a8c40905011324s2ad5e02dy47c73ae950845b54@mail.gmail.com> References: <49F4070C.2000108@gmx.de> <20090428114754.GB89235@server.vk2pj.dyndns.org> <20090430.090226.1569754707.imp@bsdimp.com> <49FA8D73.6040207@gmx.de> <49FAB322.9030103@elischer.org> <5f67a8c40905011324s2ad5e02dy47c73ae950845b54@mail.gmail.com>
next in thread | previous in thread | raw e-mail | index | archive | help
Zaphod Beeblebrox schrieb: > On Fri, May 1, 2009 at 4:30 AM, Julian Elischer <julian@elischer.org> wrote: > >> As an old-fart I have found many cases where what I thought was >> a silly style rule, turned out to save my work in some way. >> >> Christoph Mallon wrote: >> >> >> >>>> struct foo *fp; >>>> struct bar *bp; >>>> >>>> fp = get_foo(); >>>> if (!fp) return; >>>> bp = fp->bp; >>>> >>>> this can't easily be translated to the more natural: >>>> >>>> struct foo *fp = get_foo(); >>>> struct bar *bp = fp->bp; >>>> >> Well more natural for you, but not necessarily for everyone, >> and NOT the same as what is there now, as you noticed. >> >> >> >>>> since really you'd want to write: >>>> >>>> struct foo *fp = get_foo(); >>>> if (!fp) return; >>>> struct bar *bp = fp->bp; >>>> >>>> which isn't legal in 'C'. However, we have enough where this isn't >>>> >>> You're mistaken, this is perfectly legal C. See ISO/IEC 9899:1999 (E) >>> §6.8.2:1. In short: you can mix statements and declarations. >>> > Sure, but it's still very bad: If I'm not mistaken, this would mean that > "bp" would only be valid within the "if" clause --- which isn't very useful. You are mistaken. Re-read the "if": It already contains a "return;" as then-part. The declaration of "bp" has no relation to the "if". In fact this is very good: "bp" can only be used after the "if", because it is declared after it. Further, it most probably is only assigned a value once, so declaration and the signle assignment are in the same place, which aids readability and makes the code more concise. Christoph
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?49FB5C57.6050407>