types - 为什么最好使用 Glib 数据类型(例如 `gint` 而不是 `int` )?

标签 types typedef glib

这个问题在这里已经有了答案:




8年前关闭。




Possible Duplicate:
Why does glib redefine types?



在GTK+ 2.0教程中,我可以看到here以下关于数据类型的声明:

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.



我不明白这个解释的最后一部分。为什么使用 Glib 数据类型更好?

最佳答案

正如教程中提到的,它是为了确保可移植性。在新系统上构建使用 glib 的代码时,您只需修改带有 typedef 的头文件,而不是使用这些类型的代码。

C99 标准添加了固定宽度类型(int8_t、uint32_t 等),这会使 glib 类型过时,但 glib 早于 C99 标准,这可能是它拥有自己的类型集的原因。

关于types - 为什么最好使用 Glib 数据类型(例如 `gint` 而不是 `int` )?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13821332/

相关文章:

haskell - 我可以创建一个类似于 Int 的 'Looks' 仿函数数据类型吗?

c++ - 使用 typedef 声明函数有什么意义?

C++ BOOL (typedef int) vs bool 性能

c - 在结构中初始化 typedef 数组

gtk - 如何使用 GLib 使平台无关的文件路径斜杠 "/"? (GJS)

c 代码不适用于带有 float 的 Turbo C++

asynchronous - 异步方法中的类型不匹配

types - 为什么在 Rust 函数中注释类型时会出现错误 "expected type argument"?

c - "GNU libs vs Gnulib vs Gnome glib"困惑

c - 尝试通过 g_spawn_async 执行 shell 命令并读取输出