home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: jlg@cochiti.lanl.gov (J. Giles)
- Subject: Re: Question to test general C knowledge
- Message-ID: <1992Dec11.194314.20193@newshost.lanl.gov>
- Sender: news@newshost.lanl.gov
- Organization: Los Alamos National Laboratory
- References: <1992Dec10.195832.4305@leland.Stanford.EDU> <behrenss.724026637@hphalle6>
- Date: Fri, 11 Dec 1992 19:43:14 GMT
- Lines: 45
-
- In early drafts of the standard, the expression:
-
- i = ++i;
-
- was (coincidentally) well defined.
-
- The only indeterminacy in the expression was the order of the
- two assignments. And in this case, both orders actually yield
- the same result. The above expression is a special case of an
- arbitraty expression involving `++i' being assigned to `i'
- which is, in general, *NOT* the same in both orders of doing
- the assignment.
-
- The early drafts of the standard allowed such expressions, and left
- the order of the side effects unspecified. (The word "unspecified"
- has a special meaning within the standard document: the word applies
- to legal program constructs for which the standard deliberately leaves
- loose requirements.)
-
- The final version of the standard, though, contains the following
- (3.3, lines 5-7):
-
- Between the previous and next sequence point an object shall have its
- stored value modified at most once by the evaluation of an expression.
- Furthermore, the prior value shall be accessed only to determine the
- value to be stored.
-
- This explicitly disallows the above expressions. A standard conforming
- implementation is permitted to do anything it wants with programs which
- violate the standard. It could, for example, send an angry email note
- to Dennis Ritchie and then go into an infinite loop. However, acceptable
- behavior (what you would be willing to buy from a vendor, or even use
- as freeware) would be to issue a warning message and then do what the
- earlier drafts of the standard would actually have allowed.
-
- In general, the compiler can't detect all examples of violations to
- the above rule anyway:
-
- *j = ++(*i);
-
- How would the compiler necessarily know whether `i' and `j' pointed
- to the same place?
-
- --
- J. Giles
-