<div dir="ltr">Hello,<div><br></div><div>Consider the following types:</div><div><br></div><div><div><div> TPuts1 = procedure; cdecl varargs;</div><div> TPuts2 = procedure(par: string); cdecl varargs;</div><div> TPuts3 = procedure(const par: string); cdecl varargs;</div></div><div><br></div><div>this procedure:</div><div><br></div><div><div> procedure Puts(par1, par2, par3: string); cdecl;</div><div> begin</div><div>  Write(par1, ' ');</div><div>  Write(par2, ' ');</div><div>  Write(par3, ' ');</div><div>  Writeln('');</div><div> end;</div></div><div><br></div><div>and this callings:</div><div><br></div><div><div>var</div><div> PutsX: Pointer;</div><div>begin</div><div> TPuts1(@Puts)('Hello1', 'World1', 'HogeMoge1');</div><div> TPuts2(@Puts)('Hello2', 'World2', 'HogeMoge2');</div><div> TPuts3(@Puts)('Hello3', 'World3', 'HogeMoge3');</div><div> PutsX := @Puts;</div><div> TPuts1(PutsX)('Hello4', 'World4', 'HogeMoge4');</div><div> TPuts2(PutsX)('Hello5', 'World5', 'HogeMoge5');</div><div> TPuts2(PutsX)('Hello6', 'World6', 'HogeMoge6');</div><div> Readln;</div><div>end.</div></div><div><br></div><div>It compiles fine on Delphi, but in FPC I got the following error:</div><div><br></div><div>'Wrong number of parameters specified for call to "<Procedure Variable>"'.<br></div><div><br></div><div>OK, I just commented the wrong lines to be able to compile that:</div><div><br></div><div><div>begin</div><div>//  TPuts1(@Puts)('Hello1', 'World1', 'HogeMoge1');</div><div> TPuts2(@Puts)('Hello2', 'World2', 'HogeMoge2');</div><div> TPuts3(@Puts)('Hello3', 'World3', 'HogeMoge3');</div><div> PutsX := @Puts;</div><div>//  TPuts1(PutsX)('Hello4', 'World4', 'HogeMoge4');</div><div> TPuts2(PutsX)('Hello5', 'World5', 'HogeMoge5');</div><div> TPuts2(PutsX)('Hello6', 'World6', 'HogeMoge6');</div><div> Readln;</div><div>end.</div></div><div><br></div><div>But, after compile it in FPC and run the program, I got a SIGSEGV with the following stack trace (compiled on Delphi it runs properly):</div><div><br></div><div><div>#0 SYSTEM_$$_SPTR$$POINTER at :0<br></div></div><div><div>#1 fpc_ansistr_incr_ref at :0</div><div>#2 PUTS(<error reading variable>, <error reading variable>, <error reading variable>) at project1.lpr:14</div><div>#3 main at project1.lpr:25</div></div><div><br></div><div>However, if you declare it using integers, it compiles and works fine in both compilers:</div><div><br></div><div><div> TPuts = procedure(p0: Integer); cdecl varargs;</div><div><br></div><div> procedure Puts(p1, p2, p3: Integer); cdecl;</div><div> begin</div><div>  WriteLn(p1, p2, p3);</div><div> end;</div><div><br></div><div>begin</div><div> TPuts(@Puts)(1, 2, 3);</div></div><div><br></div><div>Below the generated asm to check why the first calling doesn't work in FPC if the params was declared as strings:</div><div><br></div><div><div>{$IFDEF FPC}</div><div> {$MODE DELPHI}</div><div>{$ENDIF}</div></div><div><br></div><div><div><div> TPuts = procedure(const p0: string); cdecl varargs;</div><div><br></div><div> procedure Puts(const p1, p2, p3: string); cdecl;</div><div> begin</div><div>  WriteLn(p1, p2, p3);</div><div> end;</div><div><br></div><div>begin</div><div> TPuts(@Puts)('1', '2', '3');</div></div></div><div><br></div><div>[FPC]</div><div><br></div><div><div>project1.lpr:17  TPuts(@Puts)('1', '2', '3');</div><div>004015B9 6a33           push  $0x33</div><div>004015BB 6a32           push  $0x32</div><div>004015BD b810b04000        mov   $0x40b010,%eax</div><div>004015C2 50            push  %eax</div><div>004015C3 b850154000        mov   $0x401550,%eax</div><div>004015C8 ffd0           call  *%eax</div><div>004015CA 83c40c          add   $0xc,%esp</div></div><div><br></div><div>[/FPC]<br></div><div><br></div><div>[DELPHI]</div><div><br></div><div><div>Project1.dpr.17: TPuts(@Puts)('1', '2', '3');</div><div>004060D4 6A33       push $33</div><div>004060D6 6A32       push $32</div><div>004060D8 6808614000    push $00406108</div><div>004060DD B86C5B4000    mov eax,$00405b6c</div><div>004060E2 FFD0       call eax</div><div>004060E4 83C40C      add esp,$0c</div></div><div><br></div><div>[/DELPHI]<br></div><div><br></div><div>What I'm doing wrong? Can I use this callings on FPC in the DELPHI mode?! :-/<br></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Silvio Clécio</div></div></div>
</div></div>