Order of evalution of expressions.

D'Arcy J.M. Cain darcy at druid.uucp
Thu Sep 20 11:58:10 AEST 1990


In article <6398 at castle.ed.ac.uk> elee24 at castle.ed.ac.uk (H Bruce) writes:
>I have lost my FAQ files but I'm certain this is not on it....
>Is the line
>value = *ptr - *ptr++;
>sensible C ?
> ...
>If not what is the fastest way of computing this type of expression ?
>Would the following lines be optimized by a compiler (so that value is
>not loaded twice) ?
>
>value = *ptr;
>value -= *ptr++;
Why not:
    value = 0;
	ptr++;

I suppose you meant:
	value = *ptr;
	value -= *(++ptr);
or
	value = *ptr++;
	value -= *ptr;

In any case, the order of evaluation is undefined (K&R2 pp 53) so you
you need two statements.

-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list