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

Robert White
2003-06-03T03:16:03Z

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

...OR...

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

Rob.

-----Original Message-----
From: linux-kernel-owner@vger.kernel.org
[mailto:linux-kernel-owner@vger.kernel.org]On Behalf Of Steven Cole

/*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);
}