c - Glib 类型(例如 guint)到标准 C 数据类型(例如 int)之间的类型转换

标签 c type-conversion glib

我正在使用 C 代码库,该代码库使用返回 guint 的 API 函数 ( https://developer.gnome.org/glib/stable/glib-Hash-Tables.html#g-hash-table-size )。我需要将其作为整数传递到下游。我想知道是否有任何方法可以做到这一点?

我搜索了文档和 Google,但一无所获。

最佳答案

这些 typedef 的存在本身就让我感到困惑。检查 glib/gtypes.h:

typedef char   gchar;
typedef short  gshort;
typedef long   glong;
typedef int    gint;
typedef gint   gboolean;

typedef unsigned char   guchar;
typedef unsigned short  gushort;
typedef unsigned long   gulong;
typedef unsigned int    guint;

所以unsigned intguint之间不需要转换,它们是相同的类型。

有关 unsigned intint 之间转换的常见警告适用。

关于c - Glib 类型(例如 guint)到标准 C 数据类型(例如 int)之间的类型转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46517824/

相关文章:

c - 针对 glib 进行编译时出现链接器错误...?

c - 为什么 C 关键字区分大小写?

javascript - "too much recursion"在这个用 JavaScript 编写的递归函数中 (obj2str)

c - 段错误 - 我的错误在哪里?

c - 无效 free()/delete/delete[]/realloc() 与 g_string_free()

c - 如何使用strcpy作为指针?

c - 在 C 中使用指针从字符串中删除元音

python - python中int数组中的unsigned char数组

c++ - vector push_back 显示荒谬的结果

c - 在不更改 API 且未收到警告的情况下将 const char* 转换为 char* 的正确方法是什么