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

A blog on operating systems, programming languages, testing, build systems, my own software projects and even personal productivity. Specifics include FreeBSD, Linux, Rust, Bazel and EndBASIC.

Follow @jmmv on Mastodon
Follow @jmmv on Twitter
RSS feed
0 subscribers