Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!caen!uwm.edu!linac!att!ucbvax!SCT60A.SUNYCT.EDU!sweetmr From: sweetmr@SCT60A.SUNYCT.EDU (michael sweet) Newsgroups: comp.sys.sgi Subject: Re: C compiler weirdness? Message-ID: <4597.on.Mon,.8.Apr.91.18:32:50.EDT.@sct60a.sunyct.edu> Date: 8 Apr 91 22:32:50 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 36 > only to discover that the C compiler does not increment pc until after the > function call returns in the following statement: > (*(*pc++))(); The time of increment/decrement IS compiler dependent. The only constraint with ++/-- is that '++i' increments 'i' before using that value, and 'i--' after the valuye is used. This causes MUCH heartache in the above code and the following (which I see all too often, and should NEVER be used if you want to port code to a different machine!) while (*s) *s = *++s; (or similar...) What the person probably wants to do is delete a character from a string (starting at 's'...). The idiot assumes that '*s' is evaluated for the assignment FIRST, and then 's' is incremented. A nicer way (which will get optimized away anyway) and MORE READABLE way is: while (*s) { *s = *(s+1); s++; }; The KISS philosophy is best when coding in C (keeps you from going crazy!) -Mike Sweet ------------------------------------------------------------------------------ "The only TASC (315) 724-1100 (voice) truth is that 555 French Road (315) 724-2031 (fax) there are no New Hartford, NY 13413 Internet: sweetmr@sct60a.sunyct.edu truths, only beliefs." Delphi: DODGECOLT ------------------------------------------------------------------------------