jforberg
jforberg

Reputation: 6752

What is the purpose of using glib typedefs (gint etc)?

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?

Upvotes: 3

Views: 2021

Answers (1)

Paolo Bonzini
Paolo Bonzini

Reputation: 1930

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

Upvotes: 2

Related Questions