Newsgroups: comp.std.c
Path: utzoo!henry
From: henry@zoo.toronto.edu (Henry Spencer)
Subject: Re: Unary plus
Message-ID: <1991Mar26.163306.27962@zoo.toronto.edu>
Date: Tue, 26 Mar 1991 16:33:06 GMT
References: <370@ptcburp.ptcbu.oz.au>
Organization: U of Toronto Zoology

In article <370@ptcburp.ptcbu.oz.au> michi@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@zoo.toronto.edu  utzoo!henry
