[fpc-pascal] SizeOf(File) <> SizeOf(FileRec)

Tomas Hajny XHajT03 at mbox.vol.cz
Wed May 25 00:08:41 CEST 2005

Date sent:      	Tue, 24 May 2005 20:03:28 +0200
From:           	Søren Ager <sorenager at poboxes.com>
To:             	FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
Subject:        	Re: [fpc-pascal] SizeOf(File)  <> SizeOf(FileRec)
Send reply to:  	FPC-Pascal users discussions <fpc-pascal at lists.freepascal.org>
	<mailto:fpc-pascal-request at lists.freepascal.org?subject=unsubscribe>
	<mailto:fpc-pascal-request at lists.freepascal.org?subject=subscribe>

> I have now compiled and run my first program without errors - but it
> required me to manually modify the .s file before assembly and
> linking... Here are the details:
> In so32dll.pas I have:
> function connect(sock:Longint; const s_addr:sockaddr; 
> s_addr_len:Longint):Longint; cdecl; external 'SO32DLL' index 3;
> That is called from sockets.pas:
> Function Connect(Sock:Longint;const Addr; Addrlen:Longint):Boolean;
> begin
>    Connect:=so32dll.Connect(Sock,so32dll.SockAddr(Addr),AddrLen)=0; if
>    not Connect then
>      SocketError:=so32dll.sock_errno
>    else
>      SocketError:=0;
> end;
> The code generated for that call is:
> # [214]
> # Connect:=so32dll.Connect(Sock,so32dll.SockAddr(Addr),AddrLen)=0;
>      pushl   -12(%ebp)
>      movl    -8(%ebp),%esi
>      subl    $16,%esp
>      movl    %esp,%edi
>      cld
>      movl    $16,%ecx
>      rep
>      movsb
>      pushl   -4(%ebp)
> BUT that crashes the program in SO32DLL
> I then changed it to:
> # [214]
> # Connect:=so32dll.Connect(Sock,so32dll.SockAddr(Addr),AddrLen)=0;
>      pushl   -12(%ebp)
>      pushl   -8(%ebp)
>      pushl   -4(%ebp)
> Ant then it works!!
> What do I need to do to make the compiler output that code so my
> program can run without errors?

I believe the C const construct (const declaration in a call marked 
as cdecl) is wrongly used in so32dll.connect (the meaning of this 
construct in C is different from the Pascal "const" modifier). If 
address of the record should be passed, use either "var" modifier 
(which doesn't have a particular meaning in C and is thus "safe"), or 
pass the pointer directly.

In addition, I'd be careful about alignment of record fields. It 
seems the right size of 16 is used for SockAddr now, but it could 
depend on used compiler options, so it's probably better to add 
explicit {$PACKRECORDS 1} to so32dll.pas.


More information about the fpc-pascal mailing list