Xref: utzoo comp.lang.c:15477 comp.lang.c++:2413 Path: utzoo!attcan!uunet!lll-winken!ames!xanth!ukma!rutgers!att!ulysses!andante!alice!ark From: ark@alice.UUCP (Andrew Koenig) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Re: Would *you* get caught by this one? Keywords: Assignops Message-ID: <8741@alice.UUCP> Date: 12 Jan 89 22:04:02 GMT References: <139@mole-end.UUCP> Organization: AT&T Bell Laboratories, Liberty Corner NJ Lines: 32 In article <139@mole-end.UUCP>, mat@mole-end.UUCP (Mark A Terribile) writes: > Here's a simple C question on a point that caught me recently. Would *you* > get caught? > > When is a *= b not the same as a = a * b ? Two answers: 1. When a has side-effects. For example: x[i++] *= y; is not the same as x[i++] = x[i++] * y; 2. When a is fixed-point, b is floating-point, and your compiler is broken. Many compilers are broken this way. For example: int a = 3; a *= 2.5; A number of compilers will decide to truncate 2.5 to 2 and therefore leave a equal to 6 after this is done. The right answer is, of course, 7. Or maybe 8. Definitely not 6. Do I pass? -- --Andrew Koenig ark@europa.att.com