Re: why is it so ?



Robert Gamble <rgamble99@xxxxxxxxx> wrote:
> S.Tobias wrote:

>> a[i] = one(0 || i++);

> Still has the possibility for undefined behavior, the "0 || i++" could
> be evaluated followed by i in "a[i]" before the function is called
> without an intervening sequence point.

I think it can be evaluated in one of the two ways:

(lhs, rhs)
a[i] , 0 [SEQP] i++ [SEQP] one() , return 1 [SEQP] =

or:

(rhs, lhs)
0 [SEQP] i++ [SEQP] one() , return 1 [SEQP] a[i] , =

The first case is more interesting. There's a sequence point
between evaluation of `a[i]' and `i++', so the behaviour is defined.
As for the whole expression, the behaviour is unspecified (I think).

Or is it that lhs and rhs can be evaluated in paralell? Then
there's indeed UB, but then there would be one in `i=f(++i)' too.

--
Stan Tobias
mailx `echo siXtY@xxxxxxxxxxxxxxxxxxxxxxxxxx | sed s/[[:upper:]]//g`
.



Relevant Pages

  • Re: Generic methods..
    ... T Product(T lhs, T rhs); ... T Negate(T arg); ... private static readonly IMathprovider; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: why is it so ?
    ... >>> (lhs, rhs) ... > Could you please tell me by which rule you have interleaved evaluation ... method of breaking up expressions using partial ordering by creating an ...
    (comp.lang.c)
  • Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# t
    ... I can't think of a situation where info flows from the RHS into LHS before the operation on the LHS can complete. ... However, using your analogy, it could be said that there are situations where the LHS participates in the equation independently from the RHS. ... The introduction of "var" was radically different, in that the barrier which kept each side from influencing the other was broken down. ... Can you think of any other statement or expression where info flows from the RHS into LHS before the operation on the LHS can complete? ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Suggestion for C# language: Modification to the "new" keyword - Allow type inference in C# t
    ... The RHS is no longer independant of the LHS and that is just ... Why oh why must you write MyClass TWICE: ... IF this is an assignment statement ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Now do not have "My Pictures" in window when click on start.
    ... I refer to the list on the RHS & not the ones that come up ... through being used on the LHS. ... Prev by Date: ...
    (microsoft.public.windowsxp.general)