[fpc-devel] sub byte arrays

Jonas Maebe jonas.maebe at elis.ugent.be
Tue Jul 20 12:28:46 CEST 2010

On 20 Jul 2010, at 12:03, theo wrote:

> Now I was trying if something like this would work:
> TTest=(one,two,three,four);
> TTestarray = {bitpacked} array [1..100000] of ttest;
> PTestarray = ^TTestarray;  
> var lMask: PTestarray;
> begin
> getmem(lMask, 25);

Uses new(lMask) instead, then the compiler will automatically allocate the right size for you.

> lMask^[99]:=three;
> case lMask^[99] of
>  one:writeln('one');
>  two:writeln('two');
>  three:writeln('three');
>  four:writeln('four');
> end;
> freemem(lMask);
> end;             
> It seems, to work, but it even works with commented "bitpacked".
> Shouldn't this fail?

You are writing into unallocated memory. The result of such an operation is "undefined". That means that it can to work, can crash, or anything in between.

> How can I test this? I have all checks on which
> Lazarus IDE offers, but it's still happy.

Have you enabled heaptrc? (-gh)


More information about the fpc-devel mailing list