[nem-en] Increment and decrement operators
Kamil Skalski
kamil.skalski at gmail.com
Mon Feb 27 09:26:43 CET 2006
The rule that after } there is implicit ; or , depending on context
So your ({ x++; x } + {x++; x}) is equivalent to
( { x++; x }, + { x++; x })
This is (not planned) side effect of making
if (x) {
a
}
else
b {
}
- 5
mean that we first compute a / b and then return -5 instead of
subtracting 5 from a/b
2006/2/27, Kannan Goundan <cakoose at yahoo.com>:
>
> Why are there both "x++" and "++x" if the expression doesn't return a
> value? Is it just to avoid syntax errors for those users who use one
> or the other out of habit?
>
> Also, I couldn't figure out exactly how the operator behaves. It
> seems the commas in a function call are sequence points but the part
> of an infix expression aren't, which gives weird results:
>
> class Increment
> {
> static Main() : void
> {
> mutable x : uint = 1;
>
> x = 1;
> System.Console.Write("Val: {0}", {x++; x});
> System.Console.WriteLine(", End: {0}", x);
>
> x = 1;
> System.Console.Write("Val: {0}", {++x; x});
> System.Console.WriteLine(", End: {0}", x);
>
> x = 1;
> System.Console.Write("Add: {0}", {x++; x} + {x++; x});
> System.Console.WriteLine(", End: {0}", x);
>
> x = 1;
> System.Console.Write("Add: {0}", {++x; x} + {++x; x});
> System.Console.WriteLine(", End: {0}", x);
>
> x = 1;
> System.Console.Write("Add: {0}", Add({x++; x}, {x++; x}));
> System.Console.WriteLine(", End: {0}", x);
>
> x = 1;
> System.Console.Write("Add: {0}", Add({++x; x}, {++x; x}));
> System.Console.WriteLine(", End: {0}", x);
> }
>
> static Add(a : uint, b : uint) : uint
> {
> a + b;
> }
> }
>
> -------------------
> Output:
>
> Val: 2, End: 2
> Val: 2, End: 2
> Add: 2, End: 3
> Add: 2, End: 3
> Add: 5, End: 3
> Add: 5, End: 3
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> _______________________________________________
> https://nemerle.org/mailman/listinfo/devel-en
>
--
Kamil Skalski
http://nazgul.omega.pl
More information about the devel-en
mailing list