Is something wrong with the compiler ?

Peter Holzer hp at vmars.tuwien.ac.at
Wed Oct 3 00:58:52 AEST 1990


scjones at thor.UUCP (Larry Jones) writes:

>In article <BURLEY.90Sep27013312 at world.std.com>, burley at world.std.com (James C Burley) writes:
>>    >	      a = ( int )(( unsigned ) ( a = ~0 ) >> 1 ));
>> 

>No, '=' is not a sequence point.  The question in this case is not when
>the lhs gets evaluated, but when the actual storage of the rhs into the
>lhs is done.  A compiler would be completely within its rights to store
>the final result into a and then overwrite it with ~0.

Yes, but the variable 'a' was not used afterwards, so we are not
interested in the value of a, but in the value of the complete
expression, which is IMHO well defined (The standard says in 3.3.16:
An assignment expression has the value of the left operand after the
assignment).

Expression:					Value:
(a = ~0)					(int) ~0
(unsigned)(a = ~0)				(unsigned) ~0
((unsigned)(a = ~0) >> 1)			(unsigned) MAXINT
(int)((unsigned)(a = ~0) >> 1)			(int) MAXINT
a = (int)((unsigned)(a = ~0) >> 1)		(int) MAXINT

Anything wrong with my reasoning?
--
|    _	| Peter J. Holzer			| Think of it	|
| |_|_)	| Technische Universitaet Wien		| as evolution	|
| | |	| hp at vmars.tuwien.ac.at			| in action!	|
| __/  	| ...!uunet!mcsun!tuvie!vmars!hp	|     Tony Rand	|



More information about the Comp.lang.c mailing list