Unary plus
Henry Spencer
henry at zoo.toronto.edu
Wed Mar 27 02:33:06 AEST 1991
In article <370 at ptcburp.ptcbu.oz.au> michi at ptcburp.ptcbu.oz.au (Michael Henning) writes:
>In my copy of Harbison & Steele (1987) is a section about the unary plus
>operator in ANSI-C.
>It basically states that the unary plus operator may be used to force
>a particular order of evaluation...
That was based on an obsolete ANSI draft. Unary plus no longer does
any such thing.
>If I want to enforce evaluation order by assigning to temporary variables...
No longer necessary, actually. ANSI C says that order of evaluation is as
written in the expression, unless the compiler can be sure that changing
it will have no visible effect.
> u.i = (int) u.d;
Now, on this one you do have to go via a temporary.
> tmp = (int) u.d;
> u.i = tmp;
>
>is it necessary to declare tmp as volatile to tell the optimizer not to
>get rid of it ?
No need; you don't care whether the optimizer gets rid of it. You have
satisfied the language rules, and the optimizer should not be making
changes unless it knows it is safe.
--
"[Some people] positively *wish* to | Henry Spencer @ U of Toronto Zoology
believe ill of the modern world."-R.Peto| henry at zoo.toronto.edu utzoo!henry
More information about the Comp.std.c
mailing list