[fpc-devel] Advantages of/alternatives for Inc (was: bug: Inc(v, i)/Dec(v, i))

Vinzent Hoefler JeLlyFish.software at gmx.net
Fri Jul 8 15:08:03 CEST 2005


On Friday 08 July 2005 12:39, Tom Verhoeff wrote:
> On Thu, Jul 07, 2005 at 07:47:03AM +0000, Vinzent Hoefler wrote:
> > operators. So especially with the "added" overflow check I think,
> > Inc and Dec are pretty useless functions, because the don't do
> > anything you can't accomplish by using "+" or "-" unless you have
> > very_long_and_complex_variable_names and want to save some typing
> > work.
>
> You suggest that it saves only typing,

No, I just tried to ignore that point and hoped nobody would notice. :)

> but it also simplifies
> optimization in cases where the variable is compositite, because the
> address needs to be calculated only once.

Yes, but in the same way it endorses using functions with side-effects. 
Consider

|Int_Ptr^ := Int_Ptr^ + 1;

vs.

|Inc (Int_Ptr^);

where Int_Ptr is a function returning a pointer to a different Integer 
each time it is called.

>  E.g. in one piece of code,
> I have a 13-dimensional array of integers, and I do
>
>   Inc ( A[e1, e2, ..., e13] )
>
> I don't know if modern compilers will properly optimize
>
>   A[e1, e2, ..., e13] := Succ ( A[e1, e2, ..., e13] )

They should, unless the index expressions are functions - which may have 
side-effects. See above.

> In fact, it would be nice to have a Self for arrays as well (as for
> objects), where you could write
>
>   with A[e1, e2, ..., e13] do
>     Self := Succ ( Self )

It could be more generic, if you'd allow renaming declaration like Ada 
does:

declare
   X : Integer renames A(e1, e2, ..., e13);
begin
   X := X + 1;
end;

Well, the problem with possible side-effects would remain then. Perhaps 
we should introduce the notion of a pure function (like in VHDL) to 
give the compiler a hint that it doesn't need to recalculate all that 
stuff.


Vinzent.

-- 
public key: http://www.t-domaingrabbing.ch/publickey.asc
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: signature
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20050708/7c5642b7/attachment.sig>


More information about the fpc-devel mailing list