[fpc-pascal]use of funct identifier in funct body

Balázs Csaba csbalazs at ccs.hu
Wed Sep 3 10:15:35 CEST 2003


If i know good, the result variable exists in function without declare it.
Use result instead function name.

#Tsch : Balázs Csaba 


> -----Original Message-----
> From: fpc-pascal-admin at lists.freepascal.org 
> [mailto:fpc-pascal-admin at lists.freepascal.org] On Behalf Of 
> Peter Vreman
> Sent: Wednesday, September 03, 2003 8:15 AM
> To: fpc-pascal at lists.freepascal.org
> Subject: Re: [fpc-pascal]use of funct identifier in funct body
> 
> 
> > Consider two implementations of the same function:
> >
> > Implementation 1 (the old way):
> >
> > function num_listing (n : word) : ansistring;
> > var i : word;  num : string; result : ansistring;
> > begin
> >   result := '';
> >   for i :=  to n do begin
> >     str (n, num);
> >     result := result + num; end;
> >   num_listing := result;
> > end;
> >
> > Implementation 2 (possible because fpc permits nonrecursive 
> use of the 
> > function identifer):
> >
> > function num_listing (n : word) : ansistring;
> > var i : word;  num : string;
> > begin
> >   num_listing := '';
> >   for i :=  to n do begin
> >     str (n, num);
> >     num_listing := num_listing + num; end;
> > end;
> >
> > Which performs better under fpc?  In other words, do we incur a 
> > performance penalty in #2 for the nonrecursive use of the function 
> > identifier, particularly in a tight loop as shown?  Or does the 
> > additional variable and additional assignment at the end of 
> #1 make it 
> > the loser?  I know I could run a test, but I want to hear 
> the wisdom 
> > of the compiler writers.  Thanks.
> 
> The #2 is faster. There is no penalty for the use of the 
> function identifier.
> 
> 
> 
> 
> _______________________________________________
> 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