Forum > General

Zero Sized Array at end of Records, can this test code be verified ?

(1/7) > >>

I use code in a couple of projects but I am using 3.0.4 for various reasons.

I ported over a project to the trunk install I have that still uses 3.2.0 and unless I have issues else where I am not so sure its working as it does with 3.0.4 or I have other issues related to trunk I am not seeing atm.
Below is a simple Laz project but can be done in console mode for those that like that better.
I also attached the project.

I just need to know if the values $FFFFFFFF, 1 show on output with higher than 3.0.4 fpc and if you see any issues there.

This all works fine with delphi, it's an old project.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+}{$modeSwitch advancedRecords} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type  TMyEmptyIntArray= Packed Record    Function fGetInteger(Index:Integer):Integer; inline;    procedure fSetInteger(Index:Integer;Avalue:Integer); Inline;    property Items[index:integer]:Integer read fgetInteger write fsetInteger; default;  end;  TMyIntBaseRecord = Packed Record    IntCount:DWORD;    Ints:TMyEmptyIntArray; {an Empty field at the end}  end;   PMyIntBaseRecord = ^TMyIntBaseRecord;  { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm}Function TmyEmptyIntArray.fGetInteger(Index:Integer):Integer; inline;begin  Result :=PInteger(@Self)[Index];end;Procedure TMyEmptyIntArray.fSetInteger(Index:Integer;AValue:Integer);Inline;Begin Pinteger(@Self)[Index]:=aValue;end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject);Var  T:PMyIntBaseRecord;begin  T := GetMem(SizeOf(T)+SizeOf(integer)); {Create an item plus one integer at end}  T^.IntCount := $FFFFFFFF;  T^.Ints[0]:= 1;  Caption := T^.IntCount.ToHexString+','+T^.ints[0].Tostring;  FreeMem(T);end; end.  
This is just a test app but it represents in small part of a much larger app.

Debian Linux "Buster" 64-bit Lazarus 2.0.12 FPC 3.2.0 shows FFFFFFFF,1 on the title bar after the button is pressed.

HTH, MarkMLl

FFFFFFFF,1 on Lazarus 2.0.10, FPC 3.2.0, Windows 11

FFFFFFFF,1 on Lazarus 2.3.0 (git main), FPC 3.3.1 (git main), macOS 12.0.1 (aarch64).

It is a quite neat trick if it is legal. (that self of a nested record points to the nested record, not the encompassing one)


[0] Message Index

[#] Next page

Go to full version