Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it better to use Glib data types (e.g. `gint` instead of `int`)? [duplicate]

Possible Duplicate:
Why does glib redefine types?

In the GTK+ 2.0 tutorial, I can read here the following statement about data types:

There are a few things you probably noticed in the previous examples that need explaining. The gint, gchar, etc. that you see are typedefs to int and char, respectively, that are part of the GLib system. This is done to get around that nasty dependency on the size of simple data types when doing calculations.

I don't understand the last part of this explanation. Why is it better to use Glib data types?

like image 769
remjg Avatar asked Dec 11 '12 13:12

remjg


1 Answers

As the tutorial mentions, it's to ensure portability. When building code that uses glib on a new system you'd only have to modify the header file with the typedefs, not the code that uses those types.

The C99 standard added fixed-width types (int8_t, uint32_t, etc) which would make the glib types obsolete, but glib predates the C99 standard which probably is the reason why it has its own set of types.

like image 156
Michael Avatar answered Oct 17 '22 06:10

Michael