[fpc-pascal] for..in loops?
Jonas Maebe
jonas.maebe at elis.ugent.be
Sun Nov 20 11:49:35 CET 2005
On 20 Nov 2005, at 10:57, Marco van de Voort wrote:
>> Would it be hard for the compiler to try to automatically convert
>> this new construct into an equivalent older one? .. So when it finds
>>
>> for S in ArrayOfInteger do ...
>>
>> it silently converts it to
>>
>> for i := 0 to {Count} do
>> begin
>> S := ArrayOfInteger[i];
>> ...
>>
>> ? I don't know enough about the internals to know how hard it is to
>> know the limits of the array and the type...
>
> It would require special tailored code for each type. (normal
> arrays, open
> arrays, dynarrays, pchars (length) etc etc)
All the arrays would be handled the same. The compiler can just
generate low() and high() nodes, and those will automatically do the
right thing.
Since a pchar is not an array but a pointer to a (possibly null-
terminated) array, whether or not that construct supports pchars
would be a separate decision.
Jonas
More information about the fpc-pascal
mailing list