unary +

Barry Margolin barmar at mit-eddie.MIT.EDU
Sun Mar 9 08:22:49 AEST 1986


In article <1227 at mtx5a.UUCP> esg at mtx5a.UUCP (ed gokhman) writes:
>An expression a + (b + c) may be calculated by some
>implementations as (a + b) + c. To enforce the
>intended precedence of operations one should use
>a + +(b + c).
>
>Question: what is the rational for not saying that an
>	implementation *must* respect parenthesising
>	as intended rather then providing an extra
>	operator simply to state "i mean these parenthesis" ?

I don't know what the committee's explanation is, but I agree with them
for the following reason:

Parentheses in expressions already have a meaning, that of overriding
the default precedence.  In the expression f(a)*(b+c), the parentheses
mean that the result of the function call should be multiplied by the
sum.  When writing that, the programmer ordinarily doesn't care which is
computed first, the function call or the sum.  Making parentheses have
two meanings would restrict the transformations that optimizers may
perform.

To me, this is what it means for an implementation to "respect
parenthesising as intended."
-- 
    Barry Margolin
    ARPA: barmar at MIT-Multics
    UUCP: ..!genrad!mit-eddie!barmar



More information about the Comp.lang.c mailing list