Looking at some old Open Source C codebase (everyone does that, right?) one can notice a weird convention. Procedure names and return types are split

Procnames Start Lines. But Why?

submited by
Style Pass
2025-01-02 08:30:03

Looking at some old Open Source C codebase (everyone does that, right?) one can notice a weird convention. Procedure names and return types are split on two separate lines: char * hello(char *you) { // ... } Weird convention, right?

Pros of this style are It's easy to find procedure definition with grep: just search for /^procname/. It saves some space for argument list. Especially when the return type includes qualifiers like static and const. Or something like struct long_struct_name * K&R did that. That's the reason someone on StackOverflow provided, but it's wrong. "The C Programming Language" had return type on the same line as procedure name. But! It also had main() starting the line, because it was possible to omit the "obvious" int return type. That might be where the confusion started from.

Another reason, provided by Žarko Asen over email: return type, procedure qualifications, template characteristics go on the line above the procedure's name its easier to distinguish the procedure name from the code when it resides in the beginning of a new line Highlighting the visual recognition this style gives (text preserved verbatim)

Leave a Comment