Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site decwrl.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!decwrl!dec-rhea!dec-jon!moroney From: moroney@jon.DEC (Mike Moroney) Newsgroups: net.lang.c Subject: Re: C Question Message-ID: <1609@decwrl.UUCP> Date: Thu, 11-Apr-85 00:19:51 EST Article-I.D.: decwrl.1609 Posted: Thu Apr 11 00:19:51 1985 Date-Received: Sat, 13-Apr-85 03:20:59 EST Sender: daemon@decwrl.UUCP Organization: DEC Engineering Network Lines: 25 >An inexperienced C programmer wrote a program containing the following: > > x = x++; > >Assuming that x originally had the value 5, what should the value be after >execution of the above expression ? The VAX C compiler on VMS sure threw me with its answer to this one. I compiled and ran a test program and the answer was 5. Then I looked at the machine code, and it didn't allocate ANYTHING for x, not even a register! It generated the following code for the printf statement: pushl #5 pushal $CHAR_STRING_CONSTANTS calls #2,printf It saw through the whole mess and decided that x was 5 after the "funny" assignment operation and didn't generate any machine code for the statement "x = x++;" I tried more complex programs so the compiler would not know the value of x beforehand, and it still treated "x = x++;" as a no-op. "There's a madness to my method." Mike Moroney ..decwrl!rhea!jon!moroney