On Thu, 2006-10-19 at 15:20 +0200, Jenda Krynicky wrote: > To: beginners@perl.org > Date sent: Thu, 19 Oct 2006 13:55:45 +0200 > From: Norbert Preining <[EMAIL PROTECTED]> > Copies to: Elisa Mori <[EMAIL PROTECTED]>, [EMAIL PROTECTED] > Subject: Evaluation of ++ different in C and perl? > > > Hi all! > > Maybe this has been answered before, but my searching didn't show up > > anything: The Perl Book says: Auto increment and decrement work as in > > C. So if I take this C program: #include <stdio.h> #include <stddef.h> > > int main() { > > int a; > > int b; > > a=3; > > b=(++a)+(a++); > > printf("b=%d\n",b); > > } > > it prints b=8. > > > > When I do the same in perl: > > $a = 3; > > $b = (++$a) + ($a++); > > print "b=$b\n"; > > > > It prints b=9. > > > > I checked with a friend and Java behaves like C and prints 8. > > > > Can someone enlighten us by giving an interpretation of the above > > term? > > Anyone who uses something like that begs for problems. > Just don't do that. > > Jenda > > ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== > When it comes to wine, women and song, wizards are allowed > to get drunk and croon as much as they like. > -- Terry Pratchett in Sourcery > >
Hi Norbert, Basically what Jenda said is an casual way of saying "it is undefined". If you go through the C or C++ documentation, you will find these expressions as called "undefined" Actually, the language keeps quit on the order of evaluation and the implementation is free to do it the ways it wishes i.e. in the expression a() + b() function a() or b() can be called in any order (a() then b() or b() then a()) so if a() modifies some value that b() will be using, the result will be undefined as the order decides what the result will be... I hope it helps taha