Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2026-10

composed record with private/public => documented behaviour?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Frb

The fields of the embedded record become available in the outer record. What visibility do they get (I can and have tested, and results make sense / but I want to know, if that is the designed / documented behaviour)

- fields are in the outer section? E.g T3.a is public, because the outer is public
- fields are according to the inner? E.g. T2.c is public, because the inner is public
- fields are the lowest of both? E.g. 2 access rules must both be passed to access

Also what if the outer record is NOT advanced? and does not have visibility? (that I have not tested yet)

unit Unit2; {$mode ObjFPC}{$H+}
{$ModeSwitch advancedrecords} {$ModeSwitch recordcomposition}
interface
type
   T1 = record
   private     a,b: integer;
   public      c,d: integer;
   end;
unit Unit1; {$mode ObjFPC}
{$ModeSwitch advancedrecords} {$ModeSwitch recordcomposition}
interface
uses unit2;
type
   T2 = record
   private
      contains T1;
   end;
   T3 = record
   public
      contains T1;
   end;

Reply by email

Mattias Gaertner
to Martin Frb
Martin Frb wrote 7 lines
The fields of the embedded record become available in the outer record. What visibility do they get (I can and have tested, and results make sense / but I want to know, if that is the designed / documented behaviour) [...] - fields are the lowest of both? E.g. 2 access rules must both be passed to access

lowest of both
So a strict private of an inner field is not visible to the outer record, even in the same unit. It still uses space.

Also what if the outer record is NOT advanced? and does not have visibility? (that I have not tested yet)

Default is public.

Show quoted text 23 lines
unit Unit2; {$mode ObjFPC}{$H+} {$ModeSwitch advancedrecords} {$ModeSwitch recordcomposition} interface type   T1 = record   private     a,b: integer;   public      c,d: integer;   end; unit Unit1; {$mode ObjFPC} {$ModeSwitch advancedrecords} {$ModeSwitch recordcomposition} interface uses unit2; type   T2 = record   private      contains T1;   end;   T3 = record   public      contains T1;   end;

T2 and T3 can't access a,b, even though they are exists for memory layout.

Mattias

Reply by email