home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sun-barr!ames!data.nas.nasa.gov!taligent!apple!mumbo.apple.com!zardoz.apple.com!user
- From: wingo@apple.com (Tony Wingo)
- Newsgroups: comp.sys.mac.programmer
- Subject: Re: incrementation differences/THINK C 4.0 vs. 5.0
- Message-ID: <wingo-250892130106@zardoz.apple.com>
- Date: 25 Aug 92 20:29:01 GMT
- References: <1992Aug24.221630.4730@Csli.Stanford.EDU>
- Sender: news@mumbo.apple.com (The News System)
- Followup-To: comp.sys.mac.programmer
- Distribution: na
- Organization: Apple Computer
- Lines: 50
-
- In article <1992Aug24.221630.4730@Csli.Stanford.EDU>,
- mmarx@csli.stanford.edu (Matthew Marx) wrote:]
-
- The ANSI C standard allows compilers great flexibility in order of
- evaluation. In particular, the behaviour of statements such as
-
-
- > lab[i] = temp[i++]; //****THIS IS THE PROBLEM
-
- is explicitly declared to be "undefined", meaning that different compilers
- will
- evaluate such statments differently.
-
- To quote from the 4/29/91 edition of the comp.lang.c FAQ:
-
- Any code which contains ambiguous or undifined side effects (including
- ambiguous embedded assignments has always been undefined. (Note, too,
- that a compiler's choice, especially under ANSI rules for "undefined
- behavior" may be to refuse to compile the code).
-
- (end quote)
-
- The concept of "Sequence Points" is significant here: In the ANSI C
- specification, a sequence point is one of the following operators: && || ?:
- or the comma operator. According to the spec, the order of evalutation
- within a statment between sequence points is entirely up to the compiler.
- Note that in particular, the assignment operator is not a sequence point,
- so that the is nothing that requires that the left side to the assignment
- be evaluated before the right side.
-
- A similar situation applies to function arguments (since the comma used to
- seperate argments is not a sequence point). Fragments of the form
-
- i = 0;
- printf("%d %d\n", i++, i++);
-
- will (legally) produce different outputs when compiled with different
- compilors.
-
- All of this should be covered by any good (modern) C text. Another good
- source
- of information is the C FAQ, which is periodically posted to comp.lang.c
-
-
- -tony
-
- >>usual disclaimer<<
-
- (NOTE: The article quoted above is Copyright 1988,1990, 1991 by Steve
- Summit).
-