[fpc-pascal] const records passed incorrectly
Anthony Walter
sysrpl at gmail.com
Mon Nov 16 15:01:20 CET 2009
I assume you replied so quickly you did not get the chance to read my
crafted and tested reply. You may have been typing the same time I was
:)
Please go back and read my message and note the tests section.
Jonas, why is FPC emulating C when it could simply follow the Delphi
way and prevent these incompatibilities?
It seems to me that the most logical thing is to handle it the same in
all calling conventions, which is what Delphi does (as verified
through my tests).
On Mon, Nov 16, 2009 at 8:54 AM, Martin Schreiber <fpmse at bluewin.ch> wrote:
> On Monday 16 November 2009 08:59:50 Michael Van Canneyt wrote:
>>
>> It is nowhere written in the Delphi specs that const parameters
>> are passed by reference. It is often so, but is by no means guaranteed.
>>
> There is a sentence in Delphi 7 "Language Guide" in chapter 12 "Parameters and
> function results" which possibly belongs to the theme:
> http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/programcontrolov_xml.html
> "
> Value and constant (const) parameters are passed by value or by reference,
> depending on the type and size of the parameter:
> [...]
> Sets, records, and static arrays of 1, 2, or 4 bytes are passed as 8-bit,
> 16-bit, and 32bit values. Larger sets, records, and static arrays are passed
> as 32-bit pointers to the value. An exception to this rule is that records
> are always passed directly on the stack under the cdecl, stdcall, and
> safecall conventions; the size of a record passed this way is rounded upward
> to the nearest double-word boundary.
> "
> An example from Delphi windows.pas:
> "
> type
> POverlapped = ^TOverlapped;
> _OVERLAPPED = record
> Internal: DWORD;
> InternalHigh: DWORD;
> Offset: DWORD;
> OffsetHigh: DWORD;
> hEvent: THandle;
> end;
> {$EXTERNALSYM _OVERLAPPED}
> TOverlapped = _OVERLAPPED;
> OVERLAPPED = _OVERLAPPED;
> {$EXTERNALSYM OVERLAPPED}
> [...]
> function LockFileEx(hFile: THandle; dwFlags, dwReserved: DWORD;
> nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh: DWORD;
> const lpOverlapped: TOverlapped): BOOL; stdcall;
> "
> And the C++-header:
> "
> BOOL WINAPI LockFileEx(
> __in HANDLE hFile,
> __in DWORD dwFlags,
> __reserved DWORD dwReserved,
> __in DWORD nNumberOfBytesToLockLow,
> __in DWORD nNumberOfBytesToLockHigh,
> __inout LPOVERLAPPED lpOverlapped
> );
> "
> So it is stdcall -> "An exception to this rule is that records are always
> passed directly on the stack" but LPOVERLAPPED is a pointer? There is a not
> documented special rule for const?
>
> Please don't shot me if it does not belong to the theme. ;-)
>
> Martin
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list