[fpc-devel] Re: enumerators (was: Free Pascal 2.4.2 released!)

Hans-Peter Diettrich DrDiettrich1 at aol.com
Sat Nov 13 20:56:28 CET 2010


Marco van de Voort schrieb:

> we have placed a new major release of the Free Pascal
> Compiler, version 2.4.2 on our ftp-servers.

Great :-)


> Some highlights are:
> 
> Compiler:
>   * Support D2006+ FOR..IN, with some FPC specific enhancements. Refer to
>      http://wiki.freepascal.org/for-in_loop for more information

A few notes on enumerators:

What restrictions apply to enumerators in general? IMO the loop variable 
should be treated as "const", any change to an enumerated structure 
(tree...) may result in obscure bugs. Like traversing strings seems not 
to allow to change the string, by e.g. replacing '/' by '\'.

In the array enumerator, is it possible to use an pointer into the 
array, instead of a copy of the element? This would allow to use arrays 
of Class, Record and Object types in the same way (by reference).

The comparison in the UTF-8 string example is very questionable. First 
ch(i) is not equivalent to ch, not even closely related, and the claim 
of O(N^2) operations deserves an proof - IMO it's simply wrong.


In general, what's the benefit of using enumerators? IMO a for loop 
executes faster on (linear) string and array types, where enumerator 
calls occur in for-in (see also my note on the UTF-8 string example).

Thus enumerators are useful in detail with non-linear data structures, 
like trees, linked lists, datasets(?) or collections.

DoDi




More information about the fpc-devel mailing list