home *** CD-ROM | disk | FTP | other *** search
- Path: cs.ruu.nl!usenet
- From: wsldanke@cs.ruu.nl (Wessel Dankers)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: x ^= y ^= x ^= y;
- Date: 28 Feb 96 20:13:44 +0100
- Organization: Dept of Computer Science, Utrecht University, The Netherlands
- Message-ID: <2141.6632T1213T2220@cs.ruu.nl>
- References: <1286.6624T1439T237@cs.ruu.nl> <4gij61$81i@news.ox.ac.uk>
- <3131C523.1ECC@sapiens.com> <4h075l$2go@elmer.tsc.com>
- NNTP-Posting-Host: anx1p14.cc.ruu.nl
- X-Newsreader: THOR 2.22 (Amiga TCP/IP)
-
- Bill Roberts <billr@elmer.tsc.com> wrote:
- > In article <3131C523.1ECC@sapiens.com>, Avi Lev <avil@sapiens.com> wrote:
- >>Benjamin Hutchings wrote:
- >>it'll damn right WILL work because this is proper C syntax and
- >>therefore must work, if it doesn't then your compiler had better
- >>be replaced for a real C compiler cuz it obviously isn't one.
- Damn right! Tell'm, Ben!
-
- > What expression result will be in x at the end of the expression? The
- > first one or the second one? The compiler may choose either. The c
- No it definitely CAN'T choose!
- The return value of an assignment is strictly documented and an ANSI feature!
-
- > standard specifically says that the results of this statement are
- > undefined. Consider the following:
- > x = 1;
- > y = 2;
- > x = y += x += y;
- (x += y) will have the value of the new x, so that'll be 3
- y += (3) will have the value of the new y, being 5
- x = (5) will therefore assign the value 5 to x.
-
- > Will x contain 3 or 5. It depends on what order the compiler stores
- x and y will both contain 5.
-
- > the results of the expressions in the statement. This is the same
- The order is predefined: an assignment statement is of course right-
- associative:
- (x = y) = 4
- has no meaning: how can you assign a value to a statement? A statement is no
- lvalue.
- x = (y = 4)
- however, _is_ sensible.
-
- > problem you will have with
- > i = 1;
- > x[ i++ ] = y[ i++ ];
- > What will be the value of i at the end? And which value will be used
- i++ means: increase i with one after using it. In this expression i is
- increased twice in each pass.
- while(d++ = s++);
- for two arrays d[] and s[] (for each type) is valid, though.
-
- > for which array? It is up to the compiler, and specifically declared
- > to be undefined in the c standard.
-
-
-
- --
- Wessel Dankers _\\|//_ <wsldanke@cs.ruu.nl>
- ///|\\\
- ----------------------------oOO--(_)---OOo----------------------------
- `Never imagine yourself not to be otherwise than what it might appear
- to others that what you were or might have been was not otherwise than
- what you had been would have appeared to them to be otherwise.'
-
-