[fpc-devel] Redefine FillChar() to use out parameter instead

Alexander Klenin klenin at gmail.com
Thu Nov 19 14:20:50 CET 2009


On Thu, Nov 19, 2009 at 21:02, Jonas Maebe <jonas.maebe at elis.ugent.be> wrote:

>> Ok, so how about introducing, say, FillMem procedure, which is
>> identical to FillChar
>> except that it has "out" parameter,
>
> See http://lists.freepascal.org/lists/fpc-devel/2009-November/018559.html
>
> FillMem would be a very bad name though, because it in now way suggests how
> it would differ from FillChar (a bit like the confusing AllocMem vs GetMem).
> FillCharFinalized, or FinalizeAndFill or so would be more appropriate.
>

Or simply FillCharOut?
Thinking about it some more, I am wondering -- maybe this is not the
real solution at all.

Consider:

var  a: array of String;
begin
  ... fill a with some stings ...
  FillChar(a[0], SizeOf(a) * SizeOf(string), 0);
end;

I suspect that both FillChar and FillCharOut are wrong here.
So, maybe what we actually need is FillArray(out array; const value)
half-magical function,
so that the above code might be rewritten as FillArray(a, '') ?
Another related possibility would be SetLengthInit(out array; len:
Integer; const value);

-- 
Alexander S. Klenin



More information about the fpc-devel mailing list