Re:Humans should think of sizeof() as a function, says Linus...
by krylon on Saturday May 30, 2015 @10:18AM
(#9630229)
I find parens around a return value/expression slightly annoying, but not annoying enough to have a debate over it. It doesn't make the code harder to read, IMHO.
Whitespace between a function name and the arguments is significant, however, because with a function-like macro, there must be no whitespace between the name and the opening parenthesis. I've seen the following code in production code, for example:
#include <stdlib.h>
#define free(x) free(x), x = NULL
free(ptr1); // Macro
free (ptr2); // Call free(3) directly
(Whether or not such a macro is good idea is a different question entirely, the point is that you can prevent such macro-expansion by using whitespace. Aesthetically, I find it very disturbing, though.)
Re:Humans should think of sizeof() as a function, says Linus...
by rwallace on Saturday May 30, 2015 @10:53AM
(#9630346)
You do need to omit whitespace between the name and the opening parenthesis when defining a functionlike macro, but it doesn't matter when you're calling it.
Re:Humans should think of sizeof() as a function, says Linus...
by krylon on Saturday May 30, 2015 @04:41PM
(#9631675)
I furiously looked at the C standard (C99, anyway) and the documentation to the gcc preprocessor, and have to admit somewhat embarassedly, that you are right.
The gcc preprocessor documentation clearly states:
> "If you use the macro name followed by something other than an open-parenthesis (after ignoring any spaces, tabs and comments that follow), it is not a call to the macro, and the preprocessor does not change what you have written."
Thanks for pointing this out to me!
I've seen code by others where there was always a space between the function name and its arguments. That was ugly, and really confused a function call with a statement.