Have you ever wondered about why many people writes C/C++ function definitions separating the return type from the function name? And why even style guides suggest you to do so? I'm referring to something like:


The reason behind this is to simplify searching for functions. If the function name appears in column 1, it is very easy to construct a regular expression that matches the code you are looking for.

For example: suppose that you have to locate the main function; a simple grep ^main *.c will give you a very accurate match (often unique). And in case it gives more results than desired, a grep '^main[ t]*(' *.c will return the exact match. (When using egrep, you'll need to quote the left bracket.)

Comments from the original Blogger-hosted post: