[fpc-pascal] Why in {$mode delphi} it works and in {$mode objfpc} it doesn't?
Giuliano Colla
giuliano.colla at fastwebnet.it
Mon Jan 16 19:50:34 CET 2023
I stumbled into a problem I don't understand.
I'm developing a little program for an ftp client. In order to connect
to the site I need the site address from the site name, and the libc
gethostbyname() provides the required information.
gethostbyname returns a PHostEnt type which is declared as:
> THostEnt = packed record
> h_name: PChar; { Official name of host. }
> h_aliases: PPChar; { Alias list. }
> h_addrtype: Integer; { Host address type. }
> h_length: socklen_t; { Length of address. }
> case Byte of
> 0: (h_addr_list: PPChar); { List of addresses from name
> server. }
> 1: (h_addr: PPChar); { Address, for backward
> compatibility. }
> end;
> PHostEnt = ^THostEnt;
Actually the chars h_addr points to are /hlength/ bytes to be
interpreted as an /in_addr/
In order to recover h_addr I have a line which works perfectly in Delphi
mode (inherited from an old Kylix app):
> Addr := Pin_addr(HostEnt.h_addr^);
I believed that in objfpc mode it was sufficient to change it in
> Addr := @(Pin_addr(HostEnt.h_addr^));
or in
> Addr := Pin_addr(@HostEnt.h_addr^);
but such is not the case. In both cases it flags the line with the same
error, i.e.:
Error: illegal qualifier
Hint: may be pointer dereference is missing
Fatal: Syntax error, ")" expected but "identifier H_ADDR" found
What I'm missing? How should i write that line of code to make it work
in objfpc mode?
Thanks,
Giuliano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230116/cea4e71a/attachment.htm>
More information about the fpc-pascal
mailing list