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

Jesse Pollard (jesse@cats-chateau.net)
Mon, 2 Jun 2003 07:39:12 -0500


On Sunday 01 June 2003 09:06, Larry McVoy wrote:
> > > Sometimes it is nice to be able to see function names with a
> > >
> > > grep '^[a-zA-Z].*(' *.c
> >
> > This will return 'int foo(void)', what's the problem ?
>
> You get a lot of other false hits, like globals. I don't feel strongly
> about this, I'm more wondering why this style was choosen. The way
> I showed is pretty common, it's sort of the "Unix" way (it's how the
> original Unix guys did it, how BSD did it, and how the GNU guys do it), so
> it's a somewhat surprising difference. I've never understood the logic.
> The more I think about it the less I understand it, doing it that way
> means you are more likely to have to wrap a function definition which
> is ugly:
>
> static inline int cdrom_write_check_ireason(ide_drive_t *drive, int len,
> int ireason) {
> }

Actually, that would most likely be:
static inline int cdrom_write_check_ireason(
ide_drive_t *drive,
int len,
int ireason
)
{
...
}

At least If I were doing it. Over my 20 years, I've found that many of MY
type errors are due to returning or expecting the wrong structure/variable
because I forgot the type of the function.

I rarely have to look at the parameters (though when I do, I locate them
via the function name, then scan the parameters...) sometimes just to count
the number of parameters, or the order, which is easier when the parameters
are one to a line. Either as in K&R, or the new style.

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