LongBool True = -1

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

LongBool True = -1

Anthony Walter-3
I am working with some a glib library that expects gboolean to be positive 1 for true, yet FPC emits -1 for true. Is there a compiler flag to force boolean types to emit 1 instead of -1? If so, would there possibly be any side effects with other pascal code?

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: LongBool True = -1

Free Pascal - General mailing list
Am 17.05.2018 um 23:26 schrieb Anthony Walter:
> I am working with some a glib library that expects gboolean to be
> positive 1 for true, yet FPC emits -1 for true. Is there a compiler
> flag to force boolean types to emit 1 instead of -1? If so, would
> there possibly be any side effects with other pascal code?
Why don't you use the glib2 unit which declares a correct gBoolean type
(using Boolean32 which had been introduced for that purpose) and
accordingly defined gTRUE and gFALSE?

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: LongBool True = -1

Gerhard Scholz
Afaik, the bool types (longbool, wordbool, bytebool) come from the C
language and are mostly used to interface with C libraries (for example:
windows). The definitions there are: 0 means FALSE, anything else means
TRUE. Normally C routines return a dword/word/byte filled with ones for TRUE
and expect something not 0 as TRUE. So, the definition comes from C. As long
Pascal programmers want to use libraries written in C, this definition
should not be changed in the Pascal compiler.

Regards
Gerhard

----- Original Message -----
From: "Sven Barth via fpc-pascal" <[hidden email]>
To: <[hidden email]>
Cc: "Sven Barth" <[hidden email]>
Sent: Friday, May 18, 2018 7:22 AM
Subject: Re: [fpc-pascal] LongBool True = -1


> Am 17.05.2018 um 23:26 schrieb Anthony Walter:
>> I am working with some a glib library that expects gboolean to be
>> positive 1 for true, yet FPC emits -1 for true. Is there a compiler flag
>> to force boolean types to emit 1 instead of -1? If so, would there
>> possibly be any side effects with other pascal code?
> Why don't you use the glib2 unit which declares a correct gBoolean type
> (using Boolean32 which had been introduced for that purpose) and
> accordingly defined gTRUE and gFALSE?
>
> Regards,
> Sven
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: LongBool True = -1

Free Pascal - General mailing list
Gerhard Scholz <[hidden email]> schrieb am Sa., 19. Mai 2018, 19:51:
Afaik, the bool types (longbool, wordbool, bytebool) come from the C
language and are mostly used to interface with C libraries (for example:
windows). The definitions there are: 0 means FALSE, anything else means
TRUE. Normally C routines return a dword/word/byte filled with ones for TRUE
and expect something not 0 as TRUE. So, the definition comes from C. As long
Pascal programmers want to use libraries written in C, this definition
should not be changed in the Pascal compiler.

For glib that is not true. See my quote from their documentation. Also that library is the main reason that the Boolean32 type exists (Boolean16 and Boolean64 were logical extensions then). 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: LongBool True = -1

dmitry boyarintsev
In reply to this post by Anthony Walter-3
On Thu, May 17, 2018 at 5:26 PM, Anthony Walter <[hidden email]> wrote:
I am working with some a glib library that expects gboolean to be positive 1 for true, yet FPC emits -1 for true. 

I'd think that pascal defines true as
  true = not false;
In case of unsigned integers "-1" is not an option

thanks,
Dmitry

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: LongBool True = -1

Free Pascal - General mailing list
Dmitry Boyarintsev <[hidden email]> schrieb am So., 20. Mai 2018, 04:38:
On Thu, May 17, 2018 at 5:26 PM, Anthony Walter <[hidden email]> wrote:
I am working with some a glib library that expects gboolean to be positive 1 for true, yet FPC emits -1 for true. 

I'd think that pascal defines true as
  true = not false;
In case of unsigned integers "-1" is not an option

FPC defines True as 1 for Boolean, Boolean16, Boolean32 and Boolean64 and as "-1" aka "all bits 1" for Byte Book, WordBool, LongBool and QWordBool. 

And for unsigned integers "-1" is converted to "all bits 1" as well though one needs to use a typecast (see the declaration of INVALID_HANDLE_VALUE for example). 

Regards, 
Sven 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal