yes im sorry to post this question here...
fn(a++, ++a); i.e (6,6) but different for fn(a++,a++) .
"Helge Jensen" wrote:
>
>
> Guru wrote:
>
> > I tried the following 4 line of code and answer is what I never expected.I
> > ran the code using C++ compiler(MS-Studio .net 03) also in Unix env.In fact
> > the on Unix i got the correct (or expected answer).
>
> This is probably not the correct group for this question, a c++ language
> group would be the right choice, but i'll try and answer anyway.
>
> > int a = 5;
> > fn(a++, ++a);
> > }
> > void fn(int a, int b)
> > {
> > printf("Fn : a = %d \t b = %d\n", a, b);
> > //(a,b) resp. is 6,7 on windows ( i thought it shld be 6,6,) and on unix its
> > 5,7
> > }
> > Can anyone tell me why i get b=7 in windows. the fact that parameter passing
> > in windows is right-left and in unix its left-right which makes sense when i
> > see value of variable "a" in both cases..but why c++ evaluates the value of
> > "b" twise??
>
> fn(a++, ++a);
>
> Have undefined behaviour. C++ does not define the evaluation-order of
> side-effects within sequence-points. IIRC C# imposes left-to-right
> evaulation, C++ does not.
>
> If you wish to call fn with 5,6 and then increment a twice, i recommend:
>
> fn(a, a+1);
> a += 2;
>
> Which have defined behaviour.
>
> How you could expect fn(6,6) to be invoked is unclear to me. In C#, I
> would expect fn(5, 7) to be invoked, due to the left-to-right
> evaluation-order. I don't think I would use pre/post-fix twice on the
> same value though -- just for the readability -- I would go with fn(a, a+2).
>
> --
> Helge Jensen
> mailto:helge.jensen@slog.dk
> sip:helge.jensen@slog.dk
> -=> Sebastian cover-music:
http://ungdomshus.nu <=-