[fpc-pascal] ++ and -- ( and +=, -=, ...)

Gerhard Scholz gs at g--s.de
Tue Jul 30 22:17:12 CEST 2013


(If +=, -= etc. would have been copied from Algol68 and not from C, it would 
have been written +:=  -:=, which looks more pascal-like. And the acceptance 
for these constructs would be wider, I assume. Just an optical note to that 
theme).

Beside of the question, if ++,--,+=,etc. fit into Pascal or not, there stays 
the question: is it a plus?
I expected that
a[i] += 3
compiles better than
a[i] := a[i] + 3
I expected that the computation of a[i] is done only once, but the produced 
code is the same, the address of a[i] is computed twice.
So the whole construct is only a typing saving.
Compilation done with FP 2.6.2, winxp, 32-bit)

Constructs like I++, ++I are nice shortcuts (and sometimes the code can be 
better readable), but have only a real value, if the produced code is a bit 
optimized.

standard:
    i := i + 1 ;
    a[i] := 3
with ++:
    a[++i] := 3 ;

Could save one (or two) assembler statements!

And now let's wait for people who want to see "a[++i++] := 2" in the 
language!

Gerhard

----- Original Message ----- 
From: "Marco van de Voort" <marcov at stack.nl>
To: "FPC-Pascal users discussions" <fpc-pascal at lists.freepascal.org>
Sent: Tuesday, July 30, 2013 8:37 PM
Subject: Re: [fpc-pascal] Re: ++ and --


> In our previous episode, Mattias Gaertner said:
>> > Also +=, etc are not true operators in FPC like they are in e.g. C++,
>> > but they are internally translated to "a := a + b", etc. So potential
>> > sideeffects need to be remembered here.
>>
>> That's not entirely true. For example "a:=a+b" is allowed for
>> properties, while "a+=b" is not allowed for properties.
>
> I think Sven meant that a is only evaluated once. (in case it is an
> expression). Not that it operates on all types.
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal 




More information about the fpc-pascal mailing list