Evaluation of if's

Stephen Clamage steve at taumet.com
Wed Jun 19 02:33:28 AEST 1991


daniel at sdl.mdcbbs.com writes:

>    if ((i = 1) == (i = 2)) ...

>Read these results as you will, to me it merely confirms that exepressions
>with side effects should be avoided at all costs...

Not necessarily, but one most certainly should avoid multiple side-effects
between sequence points.

>This case is an interesting example of hard to is to provide a 'complete' 
>specification for a piece of code. After all an ANSI C compiler isn't
>one of the largest pieces of software around. And, if we can't get the
>specification for something as well defined (obviously not that well
>defined as a compiler correct, where does that leave us with respect 
>to some of the larger more complex software projects around 
>(air traffic control, fly by wire ......)?

This is not a difficulty of specification.  One could provide required
semantics for the above example, but it was a deliberate choice to
leave such things undefined.  Over-specification would force compiler
implementors to generate inefficient code in many cases in order to
satisfy the requirements of pathological programs like the above.

-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list