为什么使用Glib数据类型更好(例如,使用"gint"而不是"int")? [英] Why is it better to use Glib data types (e.g. `gint` instead of `int`)?

查看:272
本文介绍了为什么使用Glib数据类型更好(例如,使用"gint"而不是"int")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
为什么glib重新定义类型?

Possible Duplicate:
Why does glib redefine types?

在GTK + 2.0教程中,我可以在此处阅读以下有关数据类型的声明:

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

在前面的示例中,您可能已经注意到了一些需要解释的东西.您看到的gint,gchar等分别是int和char的typedef,它们是GLib系统的一部分. 这样做是为了避免在进行计算时对简单数据类型大小的讨厌依赖.

我不明白此说明的最后一部分.为什么使用Glib数据类型更好?

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

推荐答案

如本教程所述,这是为了确保可移植性.在新系统上构建使用glib的代码时,只需用typedef修改头文件,而不用使用这些类型的代码即可.

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.

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

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.

这篇关于为什么使用Glib数据类型更好(例如,使用"gint"而不是"int")?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆