In article <(E-Mail Removed)>,

Richard Heathfield <(E-Mail Removed)> wrote:

> > ... then I claim that a[ i ] will be either a[ 2 ] or a[ 3 ],

> > depending on whether i++ gets evaluated first or last, but it must be

> > either one or the other.

> >

> > Wrong?

>

> Er, yeah, wrong. C doesn't actually guarantee this at all. But

> realistically, how could it have any other value? Well, I don't plan to

> work an example for you, but I recommend the following page, which gives

> some hard data on the various results you get from different compilers for

> similar expressions:

>

> http://www.phaedsys.demon.co.uk/chri...wengtips3a.htm
For i == 2 initially, one of those is probably realistically what you'll

get, but how about for other values of i?

Imagine an implementation using 64-bit ints, on a processor where

arithmetic is done using 32-bit operations, and the processor has

multiple hardware threads, which the compiler takes advantage of, and

imagine that i is a value such that i++ has changes to the bits in both

the lower and the upper 32-bits.

Neither increment nor assignment would be atomic for integers on this

setup, and the i in a[i] could be wildly off, using, say, the

pre-increment upper 32 bits and post increment lower 32 bits. It would

then be off by around 4 billion.

--

--Tim Smith