parentheses around return (houxm.356 to net.lang.c)
utzoo!decvax!cwruecmp!decot
utzoo!decvax!cwruecmp!decot
Thu Mar 31 20:50:46 AEST 1983
Re: Re: Parentheses around return (houxm.356 to net.lang.c)
If you put parentheses around everything, I wouldn't want to even TRY to read
your code, unless you run it through a LISP indenter first! Parentheses that
do not serve to clarify relatively obscure precedence only serve to clutter
the program and detract the reader's attention from what he is reading.
There is really nothing that you have to "look up" in order to understand
a statement such as
return 0;
even if you didn't know that the parentheses were necessary. Besides, there
are already enough parentheses in C; they are used for at least SIX different
semantic things by the language, and it is hard enough to pick out which are
which without adding more:
if ((j = *(int *)p++) <= sizeof(int))
return ((*(int *)())fun)());
They're used for casts, grouping, function calls, sizeof(type), abstract
function declarators, and are required syntax for many statements like
if, while, and switch.
Parentheses should be used sparingly (sparringly?) in C, but always when the
intended meaning might be missed by a reader (or the compiler).
By the way, the difference between exit and return is a large one:
exit(n);
is a function call (and thus is an expression), and
return opt_expression;
is a control flow statement, like break or continue. The strange need for
parentheses in things like if() and while() only serve to make them look
MORE like a function call, which they are NOT.
-Dave Decot
...!decvax!cwruecmp!decot
More information about the Comp.lang.c
mailing list