use of if (!cptr) and if (cptr) && a programming error

Ari Halberstadt ari at eleazar.dartmouth.edu
Sat Jul 22 02:39:05 AEST 1989


In article <8468 at batcomputer.tn.cornell.edu> lacey at tcgould.tn.cornell.edu (John Lacey) writes:
>In article <10103 at mpx2.mpx.com> erik at mpx2.mpx.com (Erik Murrey) writes:
>[Material everybody has seen n times deleted.]
>I am kind of butting in [ :-) ], but how 'bout
>        while ( ( myptr = my_func() )->x != myptr->y )
>                {
>                }

THAT WILL NOT WORK! I quote here from the book "C Traps and Pit Falls" by
Andrew Koenig (Addison-Wesley, 1989), pp. 47:
	Only the four C operators &&, ||, ?:, and , specify an order of
	evaluation.
What this means for the above code is that the machine is free to evaluate
"myptr->y" before "myptr" is assigned a value by my_func(). While it
may work with a certain compiler on a certain machine, you may wake up
tomorrow and discover some very wierd bugs!

-- Ari Halberstadt '91, "Long live succinct signatures"
E-mail: ari at eleazar.dartmouth.edu	Telephone: (603)640-5687
Mailing address: HB1128, Dartmouth College, Hanover NH 03755



More information about the Comp.lang.c mailing list