Recent

Author Topic: What compiler option causes an implied "stdcall" in Win32 ?  (Read 2627 times)

440bx

  • Hero Member
  • *****
  • Posts: 3944
What compiler option causes an implied "stdcall" in Win32 ?
« on: February 14, 2019, 09:17:12 am »
Hello,

The title says it all but, here are some details. Note: the following applies to 32bit.  In func.inc "CompareFileTime" is defined as follows (note the absence of "stdcall").
Code: Pascal  [Select][+][-]
  1. function CompareFileTime(lpFileTime1:LPFILETIME;
  2.                          lpFileTime2:LPFILETIME):LONG;
  3. external 'kernel32' name 'CompareFileTime';
In the process of "porting" some Delphi 2.0 programs, I ran into the fact that Delphi 2.0 has a different definition for that function and proceeded to make one that I thought was equivalent from a copy/paste of FPC's original definition.  I ended up with this:
Code: Pascal  [Select][+][-]
  1. function CompareFileTime(constref lpFileTime1:TFILETIME;
  2.                          constref lpFileTime2:TFILETIME):LONG;
  3. external 'kernel32' name 'CompareFileTime';
which promptly rewarded me with a SIGSEGV.

Inspecting the assembly code revealed that my definition was passing the parameters in registers instead of on the stack.  Adding "stdcall" to the definition solved the problem.

What I am puzzled about is that the definition in "func.inc" does _not_ state "stdcall" yet, it works.  What compiler directive (or anything else) caused the compiler to automatically consider the definition "stdcall" ?

(Note: I do not have any compiler mode set in the program - only directive present is {$APPTYPE GUI})  Also, this is under Win7 64bit, using FPC v3.0.4.

Thank you for your help.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: What compiler option causes an implied "stdcall" in Win32 ?
« Reply #1 on: February 14, 2019, 10:08:22 am »
In rtl/win<xx>/windows.pp

{$calling stdcall}

440bx

  • Hero Member
  • *****
  • Posts: 3944
Re: What compiler option causes an implied "stdcall" in Win32 ?
« Reply #2 on: February 14, 2019, 10:47:12 am »
In rtl/win<xx>/windows.pp

{$calling stdcall}
Thank you Marco.  I knew there had to be some setting somewhere that told the compiler to use "stdcall" but, I could find it.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

Thaddy

  • Hero Member
  • *****
  • Posts: 14204
  • Probably until I exterminate Putin.
Re: What compiler option causes an implied "stdcall" in Win32 ?
« Reply #3 on: February 14, 2019, 01:19:19 pm »
Or - more in general - from the command line  -Cc<x>     Set default calling convention to <x>
« Last Edit: February 14, 2019, 01:46:18 pm by Thaddy »
Specialize a type, not a var.

 

TinyPortal © 2005-2018