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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!stanford.edu!nntp.Stanford.EDU!dkeisen
  3. From: dkeisen@leland.Stanford.EDU (Dave Eisen)
  4. Subject: Re: Question to test general C knowledge
  5. Message-ID: <1992Dec18.203347.21977@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (USENET News System)
  7. Organization: Sequoia Peripherals, Inc.
  8. Date: Fri, 18 Dec 92 20:33:47 GMT
  9. Lines: 34
  10.  
  11. >
  12. >Now, as it happens, I have been unable to think of a way to write a
  13. >compiler such that `i = ++i' would act as if it were `i += 2'---a truly
  14. >dumb compiler will simply emit all preincrements before handling the
  15. >rest of the expression, and a truly smart one will notice that i
  16. >appears twice (and, one hopes, emit a warning) and only generate one
  17. >increment.
  18.  
  19.  
  20. Sure, a compiler that is paying attention will recognize "i = ++i"
  21. and emit a warning or do the right thing or whatever. But the
  22. semantically equivalent code:
  23.  
  24. int i;
  25.  
  26. foo ()
  27. {
  28.    bar (&i);
  29. }
  30.  
  31. bar (int *p)
  32. {
  33.    *p = ++i;
  34. }
  35.  
  36. could easily do the wrong thing and there is no sane way to
  37. make sure that it doesn't.
  38.  
  39.  
  40. -- 
  41. Dave Eisen                               Sequoia Peripherals: (415) 967-5644
  42. dkeisen@leland.Stanford.EDU              Home:                (415) 321-5154
  43.        There's something in my library to offend everybody. 
  44.           --- Washington Coalition Against Censorship
  45.