home *** CD-ROM | disk | FTP | other *** search
- Path: walt.tsc.com!not-for-mail
- From: billr@elmer.tsc.com (Bill Roberts)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: x ^= y ^= x ^= y;
- Date: 27 Feb 1996 19:21:09 -0500
- Organization: Technology Service Corporation
- Sender: Bill Roberts
- Message-ID: <4h075l$2go@elmer.tsc.com>
- References: <1286.6624T1439T237@cs.ruu.nl> <4gij61$81i@news.ox.ac.uk> <3131C523.1ECC@sapiens.com>
- NNTP-Posting-Host: elmer.tsc.com
-
- 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.
- 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
- standard specifically says that the results of this statement are
- undefined. Consider the following:
- x = 1;
- y = 2;
- x = y += x += y;
- Will x contain 3 or 5. It depends on what order the compiler stores
- the results of the expressions in the statement. This is the same
- 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
- for which array? It is up to the compiler, and specifically declared
- to be undefined in the c standard.
-
- General rule, never assign two values to the same variable in an
- expression.
-
- This same topic was the topic of a discussion for several weeks over
- on the comp.lang.c group several weeks ago.
-
-
-
-