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

Mattias Gaertner nc-gaertnma at netcologne.de
Mon Jan 16 22:12:52 CET 2023


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:
> 
> > 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/

Then either

Addr := Pin_addr(HostEnt.h_addr)^;

or

Addr := Pin_addr(HostEnt.h_addr^)^;

Mattias


More information about the fpc-pascal mailing list