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

Willy Tarreau
2003-06-01T13:36:26Z

Hi Larry !

On Sun, Jun 01, 2003 at 06:26:26AM -0700, Larry McVoy wrote:
> On Sat, May 31, 2003 at 11:56:16PM -0600, Steven Cole wrote:
> > Proposed conversion:
> >
> > int foo(void)
> > {
> > /* body here */
> > }
>
> 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 ?

> which is why I've always preferred
>
> int
> foo(void)
> {
> /* body here */
> }
>
> Is there some reason that I'm missing that the kernel folks like it the other
> way?

It will only return 'foo(void)', and you won't find its return type.
Personally, I strongly prefer getting maximum information in one line, and
I find it useful to have the return type, the name and the args together.

If you still need the name and only the name, use some sed on the output :

sed 's/^\([^ ]* \)*\([^]*\)(.*/\2/'

Cheers,
Willy