home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / mac / programm / 14505 < prev    next >
Encoding:
Internet Message Format  |  1992-08-25  |  2.2 KB

  1. Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!data.nas.nasa.gov!taligent!apple!mumbo.apple.com!zardoz.apple.com!user
  2. From: wingo@apple.com (Tony Wingo)
  3. Newsgroups: comp.sys.mac.programmer
  4. Subject: Re: incrementation differences/THINK C 4.0 vs. 5.0
  5. Message-ID: <wingo-250892130106@zardoz.apple.com>
  6. Date: 25 Aug 92 20:29:01 GMT
  7. References: <1992Aug24.221630.4730@Csli.Stanford.EDU>
  8. Sender: news@mumbo.apple.com (The News System)
  9. Followup-To: comp.sys.mac.programmer
  10. Distribution: na
  11. Organization: Apple Computer
  12. Lines: 50
  13.  
  14. In article <1992Aug24.221630.4730@Csli.Stanford.EDU>,
  15. mmarx@csli.stanford.edu (Matthew Marx) wrote:]
  16.  
  17. The ANSI C standard allows compilers great flexibility in order of
  18. evaluation.  In particular, the behaviour of statements such as
  19.  
  20.  
  21. >             lab[i] = temp[i++];  //****THIS IS THE PROBLEM
  22.  
  23. is explicitly declared to be "undefined", meaning that different compilers
  24. will 
  25. evaluate such statments differently.
  26.  
  27. To quote from the 4/29/91 edition of the comp.lang.c FAQ:
  28.  
  29.    Any code which contains ambiguous or undifined side effects (including
  30.    ambiguous embedded assignments has always been undefined.  (Note, too,
  31.    that a compiler's choice, especially under ANSI rules for "undefined
  32.    behavior" may be to refuse to compile the code).
  33.  
  34. (end quote)
  35.  
  36. The concept of "Sequence Points" is significant here:  In the ANSI C
  37. specification, a sequence point is one of the following operators: && || ?:
  38. or the comma operator.  According to the spec, the order of evalutation
  39. within a statment between sequence points is entirely up to the compiler. 
  40. Note that in particular, the assignment operator is not a sequence point,
  41. so that the is nothing that requires that the left side to the assignment
  42. be evaluated before the right side.
  43.  
  44. A similar situation applies to function arguments (since the comma used to
  45. seperate argments is not a sequence point).  Fragments of the form
  46.    
  47.    i = 0;
  48.    printf("%d %d\n", i++, i++);
  49.  
  50. will (legally) produce different outputs when compiled with different
  51. compilors.
  52.  
  53. All of this should be covered by any good (modern) C text.  Another good
  54. source
  55. of information is the C FAQ, which is periodically posted to comp.lang.c
  56.  
  57.  
  58. -tony
  59.  
  60. >>usual disclaimer<<
  61.  
  62. (NOTE: The article quoted above is Copyright 1988,1990, 1991 by Steve
  63. Summit).
  64.