[fpc-devel] Feature request/discussion - SetLengthNoInit

J. Gareth Moreton gareth at moreton-family.com
Tue Sep 15 00:49:26 CEST 2020


On 14/09/2020 19:41, Michael Van Canneyt via fpc-devel wrote:
> Better add an additional (optional) parameter SkipInit : Boolean = False;
>
> Michael.

That won't work because constructs such as "var Data: array of array of 
Byte; SetLength(Data, 25, 25);" are allowed.  Eevn if it's technically 
an intrinsic and the compiler can have customised handling, I think it 
will cause too much confusion to have an optional Boolean parameter like 
that.  Also, it might cause unnecessary additional overhead since it 
wastes a register to pass the Boolean value that, in most cases, is 
equal to False (implicitly or otherwise).

Finally, the fact it's a parameter implies that you can use a 
(non-deterministic) variable as an actual parameter, which is logically 
something that should never have a practical application in this case; 
i.e. why should initialising the data to zeroes be undecided at 
run-time? Surely you, the programmer, know what you're going to do with 
that data block.

I understand there's a risk of it breaking existing code should a unit 
have a subroutine with the name "SetLengthNoInit", although long names 
with multiple words reduces this risk, and if there is a clash, doesn't 
the compiler prioritise the subroutine defined in the unit? Should you 
want to use the internal "SetLengthNoInit" in this case, you will need 
to call "System.SetLengthNoInit", right?

Gareth aka. Kit


-- 
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



More information about the fpc-devel mailing list