Passing records and static arrays by value

Top  Previous  Next

What is translated > Routines > Parameter types > Passing records and static arrays by value

To emulate Delphi's pass-by-value semantics for records and static arrays while preserving Delphi compatibility, the translator emits parameters as a constant reference (const T&) using a renamed parameter identifier, and materializes a local copy with the original Delphi name at the start of the function body.

 

 

This guarantees that:

 

The caller's record or array variable is never modified by the callee, matching Delphi's by-value semantics.
The function body can remain mechanically unchanged, because the generated local copy keeps the original Delphi identifier.
Ownership and cleanup remain explicit, without automatic memory management, ensuring compatibility with translated Delphi code.

 

Examples:

 

procedure Foo(param: TRec);

procedure Foo(arr: TArray);

 

 

->

 

void Foo(const TRec& cparam)  // renamed input parameter

{

    TRec param = cparam;     // local copy keeps original Delphi name

    // function body uses 'param', caller is unchanged

}

 

void Foo(const TArray& xArr)  // renamed input parameter for static array

{

    TArray arr;               // local array keeps original Delphi name

    d2c::CopyStaticArray(arr, xArr);

    // function body uses 'arr', caller is unchanged

}

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content