Re: Question about style when converting from K&R to ANSI C.

Steven Cole (elenstev@mesatop.com)
01 Jun 2003 09:50:40 -0600


On Sun, 2003-06-01 at 09:09, Larry McVoy wrote:
> > /*ARGSUSED*/
> > -static unsigned long
> > -insert_bba (insn, value, errmsg)
> > - unsigned long insn;
> > - long value;
> > - const char **errmsg;
> > +static unsigned long insert_bba(
> > + unsigned long insn,
> > + long value,
> > + const char **errmsg
> > +)
> > {
> > return insn | (((insn >> 16) & 0x1f) << 11);
> > }
>
> Of the following, the original is clearly outdated so we can all agree that
> can go. I'm not real found of Linus' style either. What's wrong with the
> two traditional forms?
>
> /* ============== original ============== */
> static unsigned long
> insert_bba (insn, value, errmsg)
> unsigned long insn;
> long value;
> const char **errmsg;
> {
> return insn | (((insn >> 16) & 0x1f) << 11);
> }
>
> /* ============== linus ============== */
> static unsigned long insert_bba(
> unsigned long insn;
> long value;
> const char **errmsg;
> )
> {
> return insn | (((insn >> 16) & 0x1f) << 11);
> }
>
> /* ============== traditional ============== */
> static unsigned long
> insert_bba(unsigned long insn; long value; const char **errmsg)
> {
> return insn | (((insn >> 16) & 0x1f) << 11);
> }
>
> /* ============== traditional (lotso args) ============== */
> static unsigned long
> insert_bba(
> register unsigned const int some_big_fat_variable_name;
> unsigned long insn;
> long value;
> const char **errmsg)
> {
> return insn | (((insn >> 16) & 0x1f) << 11);
> }

Umm, I think those ";" should be "," otherwise you get a
parameter `insn' has just a forward declaration or some such error.

I have used more traditional style where the new Linus style was not
warranted. Here is the patch for fs/jfs/jfs_xtree.c:

--- bk-current/fs/jfs/jfs_xtree.c 2003-05-31 20:30:47.000000000 -0600
+++ linux/fs/jfs/jfs_xtree.c 2003-05-31 21:02:14.000000000 -0600
@@ -4225,8 +4225,7 @@
* at the current entry at the current subtree root page
*
*/
-int xtGather(t)
-btree_t *t;
+int xtGather(btree_t *t)
{
int rc = 0;
xtpage_t *p;

I haven't yet sent that to the maintainer (worked until late last night
and still getting -ENOTENOUGHCOFFEE from brain).

Anyway, I agree that more traditional styles should be used unless
otherwise indicated, but having the return type on the same line as the
function name is something I've warmed up to. And I can remember
14-character filenames and being able to print out the entire kernel in
less than 20 minutes on the line printer. That was 8 or 9 years before
linux 0.01. Yes, I'm an old-fogey.

Steven

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/