Function definitions begin on a new line

The below defines a new function.


int f()
{
....
}

A common convention, used in FreeBSD is to define it like this.


int
f(void)
{
...
}

At the beginning of my programming career, I used the first definition. Later on, I used the second. The advantage of the second definition, is that you can do this

grep ^f foo.c
or in VIM /^foo

Using regular expressions to find the function definition, as opposed to its use or declaration is very useful. This is the reason why I always use this convention of defining functions.

One response to “Function definitions begin on a new line

  1. I remember this quote

    “even the main function isn’t important enough to have its own new line” – Silvio 1998

    And now the return arg does, I’m questioning if this is the real silvio.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s