Why would anyone use gboolean (GLib) instead of the bool type?

I read code that uses gtk+ and I gboolean types like gboolean and gunichar .

While I can understand the meaning of using gunichar instead of wchar_t ( glib gunichar and wchar_t ), I cannot understand the meaning of using gboolean instead of bool .

Question: What is the point of using gboolean instead of bool ? Is there anything more than just being careful about code sequence?

It would not be so strange for me if it were used for general consistency (if you decide to use GLib , prefer to use the types defined there). However, the author of this code uses int instead of gint . Is the author simply careless?


Just add more details ( official GLib as a reference ):

  • gunichar defined as typedef guint32 gunichar

  • guint32 defined as typedef unsigned int guint32

  • gboolean defined as typedef gint gboolean

  • gint defined as typedef int gint

+6
source share
1 answer

Homogeneity and maintainability. If at a certain point in the future a new type utf8char is introduced, it will only be a matter of changing the typedef and recompiling, without having to skip thousands of lines of code to fix each use.

Also think that GLib is designed to work with a wide range of compilers, and not all of them fully comply with the latest specifications. For example, bool , wchar_t and fixed sizes cannot be allowed, since they all come with C99 and C11. In addition, the development of GLib began in 1998 (as you can see from the graph when the C99 was still in the draft, and these functions were not even standard.

+10
source

Source: https://habr.com/ru/post/988717/


All Articles