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

From: Robert White (
Date: Mon Jun 02 2003 - 22:29:25 EST

Um... ich! (ignoring the return type debate)

static unsigned long
insert_bba(unsigned long insn,
           long value,
           const char **errmsg)
   return insn | (((insn >> 16) & 0x1f) << 11);


static unsigned long insert_bba(unsigned long insn,
                                long value,
                                const char **errmsg)
   return insn | (((insn >> 16) & 0x1f) << 11);

NEVER line up the return type and the argument type like the text below. It
is mind-clobbering after a couple hundred pages.

Also, though it didn't come up, once you decide to put the arguments on
separate lines for readability never mix the styles in one function call.

int X(int A, int B,
      char **errormsg)

is "very bad". the above "looks ok" in that one instance but it isn't.
Either I have to count the arguments, or there is one per line, but never
seven arguments on five lines (if you please) as that is evil! (It is good
for driving instructors crazy too... 8-)

Also, in your automatics, it is never ok to write

   int A, *b;
or even
   int A, B;

One variable per line please.

  int A;
  int *b;

  (Especially if you are programming, or ever hope to program, tiny little
embedded systems where you really have to visualize your stack requirements.
8-) The real reason is to facilitate and encourage automatic
initializations. Particularly of classes in C++, but profoundly so in basic
C none the less. Uninitialized variables should look bare and lonely, and
perhaps even a tad wrong. (Not to mention having more than one alphabetic
character as a name, but I was being minimalist... 8-)


-----Original Message-----
[]On Behalf Of Steven Cole

-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);

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Sat Jun 07 2003 - 22:00:18 EST