Re: [BUG] Bad #define, nonportable C, missing {}

From: Momchil Velikov (velco@fadata.bg)
Date: Wed Nov 21 2001 - 10:48:25 EST


>>>>> "Andreas" == Andreas Schwab <schwab@suse.de> writes:

Andreas> "Richard B. Johnson" <root@chaos.analogic.com> writes:
Andreas> |> On Wed, 21 Nov 2001, Jan Hudec wrote:
Andreas> |>
Andreas> |> > > > *a++ = byte_rev[*a]
Andreas> |> > > It looks perferctly okay to me. Anyway, whenever would you listen to a
Andreas> |> > > C++ book talking about good C coding :p
Andreas> |> >
Andreas> |>
Andreas> |> It's simple. If any object is modified twice without an intervening
Andreas> |> sequence point, the results are undefined. The sequence-point in
Andreas> |>
Andreas> |> *a++ = byte_rev[*a];
Andreas> |>
Andreas> |> ... is the ';'.
Andreas> |>
Andreas> |> So, we look at 'a' and see if it's modified twice.

Andreas> No, the rule much stricter.

Andreas> -- Between two sequence points, an object is modified more
Andreas> than once, or is modified and the prior value is
Andreas> accessed other than to determine the value to be stored
Andreas> (6.5).

Hmm, I guess some context is missing here. Let's make it

      Between the previous and next sequence point an object shall
      have its stored value modified at most once by the evaluation of
      an expression. Furthermore, the prior value shall be accessed
      only to determine the value to be stored.

So, the above ``*a++ = byte_rev[*a]'' is undefined, because the value
of ``a'' is accessed other than to determine the value to be stored in
``a'' (as Andreas pointed out). The side effect of ``a++'' can take
place anywhere before the next sequence point (``;''), that's before
or after the array access, i.e. the statement can be evaluated as

       tmp = *a;
       *a++ = byte_rev[tmp];

 or as

       tmp = *(a+1);
       *a++ = byte_rev [tmp];

Regards,
-velco

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Fri Nov 23 2001 - 21:00:27 EST