home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18270 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.8 KB  |  37 lines

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