[fpc-pascal] H2pas tool vs others, C header translation

Sven Barth pascaldragon at googlemail.com
Sat Aug 26 13:28:56 CEST 2017


On 26.08.2017 12:57, Michael Van Canneyt wrote:
> 
> 
> On Sat, 26 Aug 2017, Sven Barth wrote:
> 
>>>
>>> Sorry for being naive. Why not simply use a boolean ?
>>>
>>> I thought all this BOOL mess was just meant to be able to interface
>>> with C
>>> libs slightly easier.
>>>
>>> Instead of
>>>
>>> If (SomeCfunction()<>0) then
>>>   DoSomethingStupid;
>>>
>>> it allows you to write - in appropriate cases - the following:
>>>
>>> if (SomeCfunction()) then
>>>   DoSomethingStupid;
>>>
>>> I don't think we should promote BOOL and friends too much. They are a
>> convenience (which IMHO should not have been introduced in the first
>> place).
>>>
>>> Promoting them to first-class Pascal citizens is IMHO a bad idea.
>>
>> Did you read the article that had been linked? That's an important point
>> that is raised in there.
> 
> I did read it.
> 
> I think the programmer *must* worry about the details and must definitely
> NOT use the booleans for anything C related. That was my point.
> 
> Attempting to cater for C code using BOOL or whatever type is misplaced.
> C does not have a boolean type.
> 
> The standard says for "if" :
> 
> "In both forms, the first substatement is executed if the expression
> compares unequal to 0."
> 
> Treat it as such.

And I say that the programmer does not need to care about it if the one
that translated the interface used the correct type. Also I very much
prefer to use "True" and "False" instead of some "INT_TRUE" or
"INT_FALSE", because that would show that FPC is not up to the job to
correctly handle this.
Please also note that I'm only talking about cases where there is indeed
a definition of a boolean type on the C side of things (e.g. the Windows
API with its BOOL as well as TRUE and FALSE definitions and GTK for
which the Boolean16, -32 and -64 types were introduced).

Regards,
Sven



More information about the fpc-pascal mailing list