Good $daytime,

> Date: Thu, 8 Apr 1999 16:39:22 +0530
> From: Anubhav Hanjura <[EMAIL PROTECTED]>
> To: UnixC <[EMAIL PROTECTED]>
> Subject: Arrays is confusing

Anubhav> Why does this code give the strange output they give?

Pardon my ignorance, but what results did you regard as strange?  It
depends heavily on what you expected :)

In general, you can't safely rely on any particular order of
calculations -- with regard to side effects.

There are four operations:
      1) '++' within lvalue;
      2) '++' within rvalue;
      3) '[]', and
      4) '='.

Dependencies are:

        ++ after []       []
        ++ after =       /  \
        =  after []     =   ++
                        |
                        ++
Possible orders are:

     a) 3 1 4 2  [] ++ = ++     means   i[0] = 1
     b) 3 4 2 1  [] = ++ ++     means   i[0] = 0
     c) 3 4 1 2  [] = ++ ++     means   i[0] = 0

However, if optimizing compiler tries to postpone evaluation of 'j'
until next usage, result most likely will be b).

  Regards,
  Willy.

--
"No easy hope or lies        | Vitaly "Willy the Pooh" Fedrushkov
 Shall bring us to our goal, | Information Technology Division
 But iron sacrifice          | Chelyabinsk State University
 Of Body, Will and Soul."    | mailto:[EMAIL PROTECTED]  +7 3512 156770
                   R.Kipling | http://www.csu.ac.ru/~willy  VVF1-RIPE

Reply via email to