home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!usc!rpi!utcsri!helios.physics.utoronto.ca!alchemy.chem.utoronto.ca!mroussel
- From: mroussel@alchemy.chem.utoronto.ca (Marc Roussel)
- Subject: Re: Question to test general C knowledge
- Message-ID: <1992Dec12.220902.21899@alchemy.chem.utoronto.ca>
- Organization: Department of Chemistry, University of Toronto
- References: <19980@ksr.com> <1992Dec11.091819.26636@thunder.mcrcim.mcgill.edu> <1992Dec11.180939.20726@crd.ge.com>
- Date: Sat, 12 Dec 1992 22:09:02 GMT
- Lines: 26
-
- In article <1992Dec11.180939.20726@crd.ge.com> volpe@ausable.crd.ge.com writes:
- >In article <1992Dec11.091819.26636@thunder.mcrcim.mcgill.edu>,
- >mouse@thunder.mcrcim.mcgill.edu (der Mouse) writes:
- >|> In article <19980@ksr.com>, jfw@ksr.com (John F. Woods) writes:
- >|> > "After
- >|> > int i = 2;
- >|> > i = ++i;
- >|> > what does i equal?"
- >|>
- >|> "Anything or nothing. 3 seems most probable, with 4 next."
- >
- >Why? The effect of the "++" is to assign 3 to i. And since the value of
- >the "++i" expression is 3, the effect of the "=" is to assign 3 to i.
- >Under what conditions would any other value be expected? (Other than,
- >of course, a vindictive compiler that detected violations of the letter
- >of the law and went out of its way to give you garbage.)
-
- Or how about a modern compiler with all the optimizations turned
- on? If the compiler doesn't actually catch this as an error, it's not
- hard to imagine that instruction rearrangement on a pipelined architecture
- might produce highly unexpected results. (Any number between 2 and 4
- seems equally likely to me.) Have you ever looked at the assembly
- language generated by a RISC compiler? Some of it is truly twisted.
-
- Marc R. Roussel
- mroussel@alchemy.chem.utoronto.ca
-