Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83 (MC830713); site vu44.UUCP Path: utzoo!linus!decvax!mcvax!vu44!keie From: keie@vu44.UUCP (Ed Keizer) Newsgroups: net.lang.c Subject: Rule of thumb for foo++ Message-ID: <297@vu44.UUCP> Date: Mon, 9-Jan-84 11:12:00 EST Article-I.D.: vu44.297 Posted: Mon Jan 9 11:12:00 1984 Date-Received: Wed, 11-Jan-84 03:33:49 EST Organization: VU Informatica, Amsterdam Lines: 23 Mark Plotnick (mit-eddie!mp) mentioned ( (foo+=1) - 1 ) as a rule of the thumb for post-increment operators like in foo++ and said that he didn't know any off-hand exceptions. Well, I met one last year that shows one of the pitfalls of overflow. Assume that foo is declared as an unsigned short and that the C compiler uses 32-bit int's. Now see what happens if we give foo the value 0xFFFF. foo++ delivers the value 0xFFFF, but ( (foo+=1) -1 ) delivers the value 0xFFFFFFFF, because the result of (foo+=1) is 0 and not 0x10000. The C reference manual is quite explicit here: "The value ___of the assignment expression___ is the value stored in the left operand after the assignment has taken place." Ed Keizer Vrije Universiteit Amsterdam ...!mcvax!vu44!keie