[fpc-pascal] Why in {$mode delphi} it works and in {$mode objfpc} it doesn't?

Giuliano Colla giuliano.colla at fastwebnet.it
Tue Jan 17 00:55:24 CET 2023


Il 16/01/23 22:23, Mattias Gaertner via fpc-pascal ha scritto:

> On Mon, 16 Jan 2023 22:12:52 +0100
> Mattias Gaertner via fpc-pascal<fpc-pascal at lists.freepascal.org>  wrote:
>
>> On Mon, 16 Jan 2023 19:50:34 +0100
>> Giuliano Colla via fpc-pascal<fpc-pascal at lists.freepascal.org>  wrote:
>>
>>> 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:
> Btw, gethostbyname is obsolete. Applications should use getaddrinfo,
> getnameinfo, and gai_strerror instead.
>
I know that it's obsolete. It's not reentrant and it is ugly. But I'm 
pretty sure that it will survive for a long time to come, because it 
provides you a check on a name *before* creating a socket. If the name 
is wrong (a typo, e.g.) you don't need to get rid of an useless socket, 
as it would happen with getaddrinfo and getnameinfo.
>>>> [...]

> Ah, I just saw gethostbyname returns a PHostEnt and Addr is Pin_addr.
>
> Then for the first address:
>    Addr := Pin_addr(HostEnt^.h_addr[0]);


IT WORKS!

But for me it's a bit obscure why in Delphi mode the right syntax is

HostEnt.h_addr^

and in objfpc

HostEnt.h^.h_addr[0]

I can understand the first caret (Delphi puts it there implicitly) but 
not the rest.

However thanks a lot. If gethostbyname can be a little obsolete, Delphi 
mode for me is much more obsolete and deprecated!

Giuliano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20230117/fdf817e0/attachment.htm>


More information about the fpc-pascal mailing list