[fpc-pascal] cdecl calling and const parameters - was SizeOf(File) <> SizeOf(FileRec)
Søren Ager
sorenager at poboxes.com
Wed May 25 09:29:00 CEST 2005
Tomas Hajny wrote:
> 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).
I am programming in Pascal so I can't see what C has to do with it ;-)
I am only interested in changing the caling convention - not the meaning
of the const which should be the same as var - with the exception that
you are not allowed to change the parameter. So you are saying there is
no way to make it behave like that? :-(
> If address of the record should be passed, use either "var" modifier
That works - but it is not optimal as I have to double buffer all calls
in the standard units from const to var. Sockets.pas:
Function Connect(Sock:Longint;const Addr; Addrlen:Longint):Boolean;
var
sa : so32dll.SockAddr;
begin
sa:=so32dll.SockAddr(Addr);
Connect:=so32dll.Connect(Sock,sa,AddrLen)=0;
if not Connect then
SocketError:=so32dll.sock_errno
else
SocketError:=0;
end;
And it gets worse when I have an untyped buffer (as send does) - then I
will have to allocate memory - copy the contents - call the dll -
deallocate...
> depend on used compiler options, so it's probably better to add
> explicit {$PACKRECORDS 1} to so32dll.pas.
Done
Take care,
Soren
More information about the fpc-pascal
mailing list