mel (03/26/83)
John, you are throwing an ego trip at those of us who don't code in C all day. Your "inside knowledge" that return is a compiler construct, not a function call should not be a point of pride, or even used. What is the syntactic difference between exit and return, except one must be exit(n) and the other can be return n? I put parentheses around EVERYTHING, and advocate that everybody else should, also. Why should someone else reading your code, someone not as "knowledgeable" as yourself, have to look up operator precedence rules and obscure "features" of the language to understand your program? Mel Haas , houxm!mel
mat (03/28/83)
(Burners on) Mel, excess parentheses are one of the leading causes of difficult--to--read code. When parentheses are used sparingly, their presence alerts the reader (read maintanance programmer) to the fact that things are NOT behaving according to the default rules. When everything is parenthesized, one must muck through more detail and hold more detail in memory in order to understand the function of a program. And most of the operator precedence of C is well done -- only the bitwiise operators are out of place. Is this a legacy of PL/1 ? (Burners off) Regarding the return statement -- I don't much care whether or not parentheses are used, but I would expect a programmer to know that a return was a part of the language, and an exit call a part of the support environment. BTW, I don't use the parens. 'Druther not clutter up the page any more than it has to be. Duke of DeNet Mark Terribile -hou5e!mat
tim (03/28/83)
Remember that long and horribly boring discussion of indentation styles back when this group got started? See any resemblance to it in the current discussion of parentheses in return statements? (If not, try "no one really cares", "matter of opinion", and "won't convince anyone to change their minds" for starters.) Please abort it before it makes the group unreadable again. By the way, did you know that you can return from main, and the value you return is the exit code? Makes exit(n) somewhat less attractive for most applications. Tim Maroney
wapd (03/29/83)
My two cents worth : Things are "better" in a language if unnecessary inconsistencies are avoided. The syntax of "return" should be the same as that of "exit" because, from the users or programmers point of view, the actions are similar. A value is being used in some action that is represented as a name (return or exit). This doesn't come under the heading of "wanting EVERYTHING to have parentheses around it". It comes under the heading of "least astonishment". Why does "main" have the syntax of a function ? If you return from it, you are in trouble. If you fall off the end of it, you exit instead of returning. Where do its arguments appear from ? My vote for inconsistency of the year is "static". In a function, it means "not automatic". Outside of a function, it means "private". Bill Dietrich houxj!wapd
jimb (03/29/83)
It's not necessary to change C to enjoy this "feature". Simply supplying the optional parentheses should cause any C compiler to detect the "missing" semicolon, though the message may not be as nice as one would like. The vax/pcc compiler flags the following fragment as a "syntax" error on the line containing "printf". return (expr) printf (..); If you don't like the parentheses, you can omit them. I usually omit the parentheses so return is better distinguished from function calls. I generally find distasteful any nit-picking about language syntax. I've learned many languages, and find that, after some practice, I can adapt to most any syntactic conventions. In the long run, most time is spent debugging my own logic. I submit that most languages provide comparable support for this, independently of the quality of a person's individual programming abilities. Jim Besemer ucbvax!tektronix!tekmdp!jimb Design Automation Division Tektronix
bernie (03/30/83)
There is *more* than a syntactic difference between exit() and return; one is a built-in part of the language, while the other is a function peculiar to the local computing environment. (There's nothing to say that every environment that supports C must provide an exit() function, though most do out of convenience). Anyone who programs in C ought to know the distinction between the two, just as Fortran programmers ought to know that CONTINUE is not a valid variable. --Bernie Roehl ...decvax!watmath!watarts!bernie
decot (04/01/83)
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
trb (04/02/83)
I think that instead of worrying about whether we should put parentheses around the argument to return, we could get rid of lots of C syntax problems by forcing people not to cross line boundaries with statements. I used to use a language that worked that way and it was really cool. April fools, Andy Tannenbaum Bell Labs Whippany, NJ (201) 386-6491