Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-04

header translation question: I need an int sized boolean

9 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bernd

Hi,

I have this from the GLIB heads:

typedef int    gint;
typedef gint   gboolean;

Now I need a few packed records with such gboolean types in them. On my i386 I am now just using

type
  GBoolean = LongBool;

Just to get something¹ up and running before the day was over. Unfortunately I cannot yet test this on 64 bit and I'm not a C programmer also. I assume on 64 bit architectures the int will be 64 bit, is this correct? I haven't found anything in the ctypes unit, should I use ifdefs to define my GBoolean or is there a more elegant one-liner to easily get such an integer sized bool?

Bernd

_______
¹ I am trying to find out whether I can make a libpurple (Pidgin) plugin in FPC without needing these headers and gcc at all and without jumping through too many hoops. Now I have it loading, registering and unloading without a crash already :-) its not as complicated as I initially assumed.

Reply by email

David W Noon
to Bernd

On Sun, 22 Apr 2012 01:54:17 +0200, Bernd wrote about [fpc-pascal] header translation question: I need an int sized boolean:

Show quoted text 15 lines
I have this from the GLIB heads: typedef int gint; typedef gint gboolean; Now I need a few packed records with such gboolean types in them. On my i386 I am now just using type GBoolean = LongBool; Just to get something¹ up and running before the day was over. Unfortunately I cannot yet test this on 64 bit and I'm not a C programmer also. I assume on 64 bit architectures the int will be 64 bit, is this correct?

No.

There should be one of two C macros defined by your 64-bit compiler: __LP64__ or __LLP64__ . The first one implies that for 64 bits you use "long int" and the second one implies that you use "long long int"; they also imply that all pointers are 64-bit. Without any "long" prefix an integer remains 32-bit.

GCC defines __LP64__ . But an undecorated "int" declares a 32-bit integer.

I haven't found anything in the ctypes unit, should I use ifdefs to define my GBoolean or is there a more elegant one-liner to easily get such an integer sized bool?

Leave it as you currently have it.

Regards, Dave [RLU #314465] ======================================================================= (David W Noon) =======================================================================

Reply by email

Bernd
to David W Noon

2012/4/22 David W Noon :

 Without any "long" prefix an integer remains 32-bit. [...] Leave it as you currently have it.

Thanks, this sounds good.

For the record: I was trying to port this:
http://developer.pidgin.im/wiki/CHowTo/BasicPluginHowto to FPC and now I have posted the results of yesterday's experiments after it finally started working for the first time in the Lazarus forum:
http://www.lazarus.freepascal.org/index.php/topic,10795.msg91177.html#msg91177 just in case somebody else also wants to experiment with it and doesn't have to start from zero.

Bernd

Reply by email

Marco van de Voort
to Bernd: I have this from the GLIB heads: typedef int gint; typedef gint gboolean; Now I need…

In our previous episode, Bernd said:

Show quoted text 7 lines
I have this from the GLIB heads: typedef int gint; typedef gint gboolean; Now I need a few packed records with such gboolean types in them. On my i386 I am now just using

That's afaik a wrong translation. longbool are true 0, while gboolean, like Pascal booleans, are only true =1.

FPC 2.6.0+ introduced boolean8/16/32/64 types for this.

Reply by email

Bernd
to Marco van de Voort
Marco van de Voort wrote
FPC 2.6.0+ introduced boolean8/16/32/64 types for this.

I just saw it in gtypes.inc and wondered what this is, this is the first time I have seen these new boolean types. Also Lazarus does not yet know about them in the code completion.

Reply by email

Marco van de Voort
to Bernd

In our previous episode, Bernd said:

Show quoted text 6 lines
Am 22. April 2012 17:39 schrieb Marco van de Voort : > gboolean, > like Pascal booleans, are only true =1. Just out of curiosity, how can they enforce this for the C compiler with only some definitions in a header file?

I don't know, I don't use GTK with C. It could be that they simply don't, and leave it up to the programmer to proper compare with gfalse and gtrue.

I only know that in some cases the longbool situation went wrong, and while that was fixable by doing somebool=gtrue, it had other problems.

I was halfway fixing with gtrue when (IIRC) Florian committed the boolean<xx> stuff.

Reply by email