Path: utzoo!attcan!uunet!mcvax!unido!uniol!henseler From: henseler@uniol.UUCP (Herwig Henseler) Newsgroups: comp.lang.c Subject: Re: What's a C expert? Message-ID: <757@uniol.UUCP> Date: 16 Aug 89 14:09:41 GMT References: <12214@well.UUCP> <6057@microsoft.UUCP> <1336@atanasoff.cs.iastate.edu> Distribution: all Organization: University of Oldenburg, W-Germany Lines: 33 > }> What do you need to know to be an expert C programmer? > }How about ... understands why a[i] equals i[a] and CAN EXPLAIN IT, That's really nice, but not all compiler are willed to compile it... Another nice example: int i = 0; i += ++i + i++; printf( "%d\n", i ); Now explain what can happen..... Solution: Every number between 1 and 5 (inclusive) is legal! Our compiler produces '5' and I had to look at the machine-code to figure out why: i += ++i + i++; expands to (our compiler evaluates from left to right): /* a. b. c. */ i = ++i + i++ + i; First i is incremented at pos. a, i equals 1 and is incremented at pos. b. Now position b evaluates to 1 and pos a to 2 (!! strange but legal !!). At pos. c i has the value 2. Now 2+1+2 results in 5. Voila! (The explanation of the four other possible results are left as an exercise for junior C-experts :-) bye, Herwig -- ** Herwig Henseler (CS-Student) D-2930 Varel, Tweehoernweg 69 | Brain error- ** ** EMail: henseler@uniol.UUCP (..!uunet!unido!uniol!henseler) | core dumped **