Path: utzoo!utgpu!water!watmath!clyde!ima!cfisun!lakart!dg From: dg@lakart.UUCP (David Goodenough) Newsgroups: comp.lang.c Subject: Re: Unnecessary parenthesis Message-ID: <175@lakart.UUCP> Date: 8 Jul 88 19:27:16 GMT References: <326@marob.MASA.COM> Organization: Lake - The systems people Lines: 28 From article <326@marob.MASA.COM>, by daveh@marob.MASA.COM (Dave Hammond): > Is different code produce by the compiler for "return n" and "return(n)" ? > > How about "if (x>1 && y<2)" and "if ((x>1) && (y<2))" ? Do unnecessary > parenthesis generate more code ? These two expressions *_SHOULD_* generate the same code on any decent self respecting compiler (They do even on BDS C 1.43 under CP/M :-). It is worth noting that this is a weakness of RD parsers: the amount of work incurred by unnecessary parentheses is quite considerable, especially in a language such as C, with 15 levels of operator precedence. As for LR parsers I don't know - I have not studied them to the same degree. The reason why people tend to parenthesize where it is not needed is to increase clarity. Quick - do these two mean the same: if ((a == 1 && b == 2) || (c == 3 && d == 4)) if (a == 1 && b == 2 || c == 3 && d == 4) In the first case, my intention is much clearer (to myself included). I believe (as do many others) that parentheses serve a double function: overriding the normal precedence of operators, AND making things readable. -- dg@lakart.UUCP - David Goodenough +---+ | +-+-+ ....... !harvard!cca!lakart!dg +-+-+ | +---+