Rick wrote, On 28/12/07 19:42:
> On Thu, 27 Dec 2007 03:45:29 -0800 (PST), jeniffer
> <> wrote:
>
>> I want to know why is a[i] = i++ ; wrong? People say that it is
>> because of different parsing during compilation.Please explain
>> technically why it is wrong/behaviour undefined?
>
> Good afternoon, Jeniffer.
>
> Looks like I'm the only one here who's going to give you a straight
> answer without chastising you first for not reading the FAQ.
Well, since it is only polite to read the FAQ first and the FAQ is more
accurate than your answer...
Actually, *you* should have read the FAQ first as well so that you could
provide correct information.
> The answer is that C does not guarantee order of evaluation.
> Therefore, i++ might be evaluated first, before being applied as an
> index into a[], or it might be evaluated last, and the compiler is
> perfectly free to do it either way.
No, that is NOT why it is undefined. As others have stated it is
undefined because i is modified and read for a reason other than
determining the new value between sequence points. This means that the
compiler is NOT restricted to the possibilities you suggested.
> So, if i started off as, say, 2, then a[i] might be a[2], or it might
> be a[3].
Or it could be 97 or cause your program to crash or anything else. Yes,
there *are* reasons it could crash a program on some possible
implementations.
> Hope this helps...
I hope I have corrected your misconceptions.
--
Flash Gordon