2

EDIT: I'm specifically asking about the non-fixed size types, not the fixed-size types. As stated, I understand the (historical) purpose for using them.

In my current codebase I commonly see Glib types like gint, guint, gboolean, gpointer etc.

Looking in the header file they are just new names for the standard C types:

typedef char   gchar;
typedef short  gshort;
typedef long   glong;
typedef int    gint;
typedef gint   gboolean;
typedef void* gpointer;

What is the purpose of using these typedefs? It seems to me we are just hiding information, especially in the case of gpointer which is typedeffed to a non-pointer signature. Also gboolean which is used instead of the C standard booleans from C99 (_Bool is defined as a one-byte type, not as int in e.g. the AMD64 Sys V ABI and ARMv7 ABI).

I understand the purpose of fixed-width typedefs before we had stdint and perhaps also gboolean before there was stdbool but is there any real benefit of using these types in 2015?

jforberg
  • 6,537
  • 3
  • 29
  • 47
  • 3
    possible duplicate of [Why is it better to use Glib data types (e.g. \`gint\` instead of \`int\`)?](http://stackoverflow.com/questions/13821332/why-is-it-better-to-use-glib-data-types-e-g-gint-instead-of-int) – Mohit Jain Aug 10 '15 at 10:25
  • 1
    Historical portability reasons. (Before C99 was standardized) – Mohit Jain Aug 10 '15 at 10:26
  • @MohitJain That's a similar question but IMO it was not fully answered. – jforberg Aug 10 '15 at 10:31
  • 1
    @MohitJain Namely, the answers all concern the fixed-size types which is not what I'm asking about. – jforberg Aug 10 '15 at 10:34

1 Answers1

2

They were only introduced for consistency and there's no reason to use them. See this comment from Havoc Pennington (DBus and GNOME developer).

Community
  • 1
  • 1
Paolo Bonzini
  • 1,900
  • 15
  • 25