I would like to know Delphi equivalent of the following operators.
++i/--i
i++/i--
i+=1/i-=1
I am aware of just Inc(i)
for i++
and Dec(i)
for i--
.
Also under the notion that Inc(i,1)
for i+=1
and Dec(i,1)
for i-=1
.
But have no idea about --i
and ++i
. Is it supported?
Are my assumptions correct? If not suggest the necessary.
Thanx in advance.
Delphi has no equivalents to any of those operators.
It is the case that inc
and dec
are similar to += and -=
but they differ in that the C/C++ versions evaluate to a value.
Whilst in C and C++ you can write
x = a[i++];
this is simply not possible with inc
in Delphi. So in Delphi I would write it as
x = a[i];
inc(i);
Having witnessed a seemingly endless supply of questions about the meaning of i++ + ++i + ++i++
I for one am happy that these operators do not exist in Delphi.
On a more serious note, you should be very wary about trying to reproduce such operators using, for example, inline functions. Once you start stringing such operators together into complex expressions you will observe unpredictable behaviour due to the fact that function evaluation order within expressions is undefined in Delphi.