Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!mit-eddie!genrad!decvax!decwrl!pyramid!prls!mips!hansen From: hansen@mips.UUCP (Craig Hansen) Newsgroups: comp.lang.c Subject: Re: Disregarding parentheses in C Message-ID: <325@dumbo.UUCP> Date: Tue, 21-Apr-87 16:29:57 EST Article-I.D.: dumbo.325 Posted: Tue Apr 21 16:29:57 1987 Date-Received: Wed, 22-Apr-87 06:16:18 EST References: <200@m10ux.UUCP> Lines: 32 Keywords: C parentheses evaluation order parsing Summary: good article - wrong conclusion In article <200@m10ux.UUCP>, mnc@m10ux.UUCP (Michael Condict) writes: [an excellent summary that distinguishes precedence, associativity, and order of evaluation] > Now finally, the main point: The source of this whole unpleasant business > is that C is defined as though its "+" and "*" operators were associative (int > or float, it doesn't matter to the discussion). That is it allows the > evaluation of "x+y+z" (or even"(x+y)+z") as though they were written > "x+(y+z)". This does not necessarily produce the same answer in the presence > of overflow and roundoff errors, hence the C operators are NOT associative, > unlike the corresponding ideal mathematical operators. Is this a bug in the > C definition? It depends on your point of view (or your programming needs), > I guess. This _is_ a bug in the C definition, particularly with respect to "float." Clearly, floating-point operations aren't associative, with particular problems in floating-point addition and subtraction. Since C doesn't check for integer overflow, most common reassociation involving integers are OK. Life would be much easier if compilers would stick to optimizations that are safe. ...aren't compilers here on this earth simply to make our lives a little easier, after all? All I'm proposing is a upward-compatible extension to ANSI C: you can conform to ANSI C and not perform these unsafe reassociations. If ANSI C prohibits these unsafe optimizations, it will be a better standard, but you can choose to build a better, safer compiler yourself. -- Craig Hansen Manager, Architecture Development MIPS Computer Systems, Inc. ...decwrl!mips!hansen