[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 23:12:13 CET 2023


Il 16/01/23 20:58, Marco van de Voort via fpc-pascal ha scritto:

>
> On 16-1-2023 20:56, Giuliano Colla via fpc-pascal wrote:
>>
>> No chance. Addr is a pointer (of type Pin_addr)
>>
>> but
>>
>> Addr := Pin_addr(HostEnt.h_addr^)
>>
>> works only if mode is Delphi. In objfpc it raises exactly the same 
>> error.
>>
>> A little bit weird, isn't it?
>>
> It depends. It assumes .h_addr is compatible with pointer.  Since Free 
> Pascal is more portable, that might be a platform dependent assumption.
>

I fail to grasp the different assumptions that the compiler makes on 
objfpc mode. If the typecast tells that the two types are compatible 
(and they are, because they're both pointers and also of the same type) 
it should write the one to the other without making any fuss! But I can 
live with it! The horrible mess they've done with gethostbyname, and the 
chars which are actually bytes is not so frequent, luckily! That's what 
happens when you don't have the "based" construct, which makes very easy 
to deal with those situations. Different structures can be based on the 
same pointer, and one "type" field, common to all structures, makes you 
pick up the right one.

Giuliano


Giuliano



More information about the fpc-pascal mailing list