[fpc-pascal] Initializing Records Automatically
ik
idokan at gmail.com
Mon Mar 24 12:03:14 CET 2008
Since when are you using fillchar on a string in Pascal ? that's a C approach.
BTW Most Pascal's string functions will stop on the first #0 they
encounter, at least the Delphi's tool that I remember.
I think he misses the entire point in his blog.
Ido
On Mon, Mar 24, 2008 at 1:20 PM, L <L at z505.com> wrote:
> http://stanleyxu2005.blogspot.com/2008/01/potential-memory-leak-by-initializing.html
>
> Interesting..
>
> So with
>
> procedure InitRecord(out R; SizeOfRecord: Integer);
> begin
> FillChar(R, SizeOfRecord, #0);
> end;
>
> Even if it has dynamic array, ansistrings, shortstrings, integers,
>
> I assume it is okay to initialize it this way (assumptions are bad).
>
> The problem: initializing records with automated types by going through
> each and every field is error prone because if you expand the record
> later on with more fields, you might forget to update your custom init
> procedure..
>
> And a question: does old borland style "object" initialize anything as
> classes do? Stack based ones? heap ones?
>
> Interesting pondering: what would be nicee is an auto initialized record:
>
> procedure example;
> var something: somerec autoinit;
> begin
> end;
>
> Many times I find myself initializing stuff tediously and error prone
> when you do it a human way without automation.
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
--
http://ik.homelinux.org/
More information about the fpc-pascal
mailing list