Path: utzoo!attcan!uunet!lll-winken!ncis.llnl.gov!helios.ee.lbl.gov!pasteur!ucbvax!decwrl!labrea!rutgers!rochester!pt.cs.cmu.edu!b.gp.cs.cmu.edu!ralf From: ralf@b.gp.cs.cmu.edu (Ralf Brown) Newsgroups: comp.sys.ibm.pc Subject: Re: TC2.0 bugfree ? Message-ID: <4075@pt.cs.cmu.edu> Date: 20 Jan 89 18:11:37 GMT References: <3785@druwy.ATT.COM> Organization: Carnegie-Mellon University, CS/RI Lines: 38 In article <3785@druwy.ATT.COM> rhm@druwy.UUCP (MasseyR) writes: }No bugs in TC2.0 ? } }This small model C program : } }sub( cp ) }unsigned char *cp; }{ } int i; } i = (*cp++ << 8) + *cp++; }} } }generates the following code fragment (I left out some of the .asm): [fragment omitted] } }note that si (i.e. cp) is not incremented between references }but instead after both references. That is not a bug. K&R explicitly state that the compiler may do the increment any time between the value's use and the next sequence point (comma, end of statement, etc.). You cannot rely on order-of-execution within an expression, since the compiler is free to rearrange things as it sees fit. The code fragment i = 4 ; printf("%d",i++ + i++ + i++) ; has three legal results: 12 14 15 depending on how many of the increments are deferred until after the additions. -- {harvard,uunet,ucbvax}!b.gp.cs.cmu.edu!ralf -=-=- AT&T: (412)268-3053 (school) ARPA: RALF@B.GP.CS.CMU.EDU |"Tolerance means excusing the mistakes others make. FIDO: Ralf Brown at 129/31 | Tact means not noticing them." --Arthur Schnitzler BITnet: RALF%B.GP.CS.CMU.EDU@CMUCCVMA -=-=- DISCLAIMER? I claimed something? --