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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!ornl!utkcs2!darwin.sura.net!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!sun-barr!cs.utexas.edu!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  3. From: jlg@cochiti.lanl.gov (J. Giles)
  4. Subject: Re: Question to test general C knowledge
  5. Message-ID: <1992Dec11.194314.20193@newshost.lanl.gov>
  6. Sender: news@newshost.lanl.gov
  7. Organization: Los Alamos National Laboratory
  8. References: <1992Dec10.195832.4305@leland.Stanford.EDU> <behrenss.724026637@hphalle6>
  9. Date: Fri, 11 Dec 1992 19:43:14 GMT
  10. Lines: 45
  11.  
  12. In early drafts of the standard, the expression:
  13.  
  14.    i = ++i;
  15.  
  16. was (coincidentally) well defined.
  17.  
  18. The only indeterminacy in the expression was the order of the 
  19. two assignments.  And in this case, both orders actually yield 
  20. the same result.  The above expression is a special case of an
  21. arbitraty expression involving `++i' being assigned to `i'
  22. which is, in general, *NOT* the same in both orders of doing 
  23. the assignment.  
  24.  
  25. The early drafts of the standard allowed such expressions, and left 
  26. the order of the side effects unspecified.  (The word "unspecified" 
  27. has a special meaning within the standard document: the word applies 
  28. to legal program constructs for which the standard deliberately leaves 
  29. loose requirements.)
  30.  
  31. The final version of the standard, though, contains the following 
  32. (3.3, lines 5-7):
  33.  
  34.    Between the previous and next sequence point an object shall have its
  35.    stored value modified at most once by the evaluation of an expression.
  36.    Furthermore, the prior value shall be accessed only to determine the
  37.    value to be stored.
  38.  
  39. This explicitly disallows the above expressions.  A standard conforming
  40. implementation is permitted to do anything it wants with programs which
  41. violate the standard.  It could, for example, send an angry email note
  42. to Dennis Ritchie and then go into an infinite loop.  However, acceptable
  43. behavior (what you would be willing to buy from a vendor, or even use
  44. as freeware) would be to issue a warning message and then do what the
  45. earlier drafts of the standard would actually have allowed.
  46.  
  47. In general, the compiler can't detect all examples of violations to 
  48. the above rule anyway:
  49.  
  50.    *j = ++(*i);
  51.  
  52. How would the compiler necessarily know whether `i' and `j' pointed
  53. to the same place?
  54.  
  55. -- 
  56. J. Giles
  57.