C99: Suggestions for style(9)
Zaphod Beeblebrox
zbeeble at gmail.com
Fri May 1 20:48:48 UTC 2009
On Fri, May 1, 2009 at 4:30 AM, Julian Elischer <julian at 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.
More information about the freebsd-hackers
mailing list