GLib中文文档 — GLib基本类型(Basic Types )

本文翻译了GLib库的基本类型文档,包括布尔型、指针、字符型等常见类型,旨在提供给需要使用GLib库的开发者更便捷的中文资源。文中详细介绍了每种类型的特点及用途,特别强调了GLib库中的一些特殊类型如gsize、gssize等,旨在帮助开发者更好地理解并应用这些类型。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前段时间用linux C写联机服务器,用到GLib库。
在网上找了很久,发现这么经典的库,居然没有中文文档。
于是花了几天的时间,翻译了常用的GLib库文档。
水平有限,很多地方都是直译,至少比看英文文档要方便些,有错误的地方欢迎指正。
也希望能给需要用GLib的朋友一些帮助。

如果本文有更新,请访问下面的地址:http://www.flashcat.com.cn/blog/read.php?32

Basic Types 基本类型
基本类型 — 标准的Glib类型,定义的非常易用和简便。

Synopsis 大纲

#include <glib.h>

typedef             gboolean;
typedef             gpointer;
typedef             gconstpointer;
typedef             gchar;
typedef             guchar;

typedef             gint;
typedef             guint;
typedef             gshort;
typedef             gushort;
typedef             glong;
typedef             gulong;

typedef             gint8;
typedef             guint8;
typedef             gint16;
typedef             guint16;
typedef             gint32;
typedef             guint32;

#define             G_HAVE_GINT64
typedef             gint64;
GLIB_VAR            guint64                             ();
#define             G_GINT64_CONSTANT                   (val)
#define             G_GUINT64_CONSTANT                  (val)

typedef             gfloat;
typedef             gdouble;

typedef             gsize;
typedef             gssize;
typedef             goffset;


Description 描述
定义一些普通使用类型,可分为4组:
1.不属于标准C的新类型:gboolean, gsize, gssize.
2.可以在任何平台使用的整数:gint8, guint8, gint16, guint16, gint32, guint32, gint64, guint64.
3.与标准C相似但更好用的类型:gpointer, gconstpointer, guchar, guint, gushort, gulong.
4.与标准C基本一致的类型:gchar, gint, gshort, glong, gfloat, gdouble.

Details 详细说明
gboolean
typedef gint   gboolean;
标准的boolean类型。它只储存两个值:TRUE和FALSE

gpointer
typedef void* gpointer;
无类型的指针。Gpointer比 void*更好看和更好用。

gconstpointer
typedef const void *gconstpointer;
一个常数的无类型指针。指针的值不能被更改。
典型的使用子函数原型上,指出指针所指向的数据是不能被函数更改的。

gchar
typedef char   gchar;
和标准C的char类型一致。

guchar
typedef unsigned char   guchar;
和标准C的 unsigned char一致。

gint
typedef int    gint;
类似标准C的int类型。其值能被设置G_MININT 到 G_MAXINT范围。

guint
typedef unsigned int    guint;
类似标准C的unsigned int类型。其值能被设置0到 G_MAXUINT的范围。

gshort
typedef short  gshort;
类似标准C的short类型。其值能被设置G_MINSHORT 到 G_MAXSHORT范围。

gushort
typedef unsigned short  gushort;
类似标准C的unsigned short类型。其值能被设置0到 G_MAXUSHORT的范围。

glong
typedef long   glong;
类似标准C的long类型。其值能被设置G_MINLONG 到 G_MAXLONG范围。

gulong
typedef unsigned long   gulong;
类似标准C的unsigned long类型。其值能被设置0到 G_MAXULONG的范围。

gint8
typedef signed char gint8;
在任何平台上都保证是一个有符号8位整数。
其取值返回为 -128 到 127

guint8
typedef unsigned char guint8;
在任何平台上都保证是一个无符号8位整数。
其取值返回为 0 到 255

gint16
typedef signed short gint16;
在任何平台上都保证是一个有符号16位整数。
其取值返回为 -32,768 到 32,767

guint16
typedef unsigned short guint16;
在任何平台上都保证是一个无符号16位整数。
其取值返回为 0 到 65,535

gint32
typedef signed int gint32;
在任何平台上都保证是一个有符号32位整数。
其取值返回为 -2,147,483,648 到 2,147,483,647

guint32
typedef unsigned int guint32;
在任何平台上都保证是一个无符号32位整数。
其取值返回为 0 到 4,294,967,295

gint64
G_GNUC_EXTENSION typedef signed long long gint64;
在任何平台上都保证是一个有符号64位整数。
其取值返回为 -9,223,372,036,854,775,808 到 9,223,372,036,854,775,807

guint64 ()
GLIB_VAR            guint64                             ();
在任何平台上都保证是一个无符号32位整数。
其取值返回为 0 到 18,446,744,073,709,551,615

G_GINT64_CONSTANT()
#define G_GINT64_CONSTANT(val)  (G_GNUC_EXTENSION (val##LL))
This macro is used to insert 64-bit integer literals into the source co
de.
(不太懂)
val :  a literal integer value, e.g. 0x1d636b02300a7aa7U.

G_GUINT64_CONSTANT()
#define G_GUINT64_CONSTANT(val)  (G_GNUC_EXTENSION (val##ULL))
This macro is used to insert 64-bit unsigned integer literals into the source co
de.
(不太懂)
val :  a literal integer value, e.g. 0x1d636b02300a7aa7U.
Since 2.10

gfloat
typedef float   gfloat;
类似标准C的float类型。其值可以设置-G_MAXFLOAT 到 G_MAXFLOAT范围

gdouble
typedef double  gdouble;
类似标准C的double类型。其值可以设置-G_MAXDOUBLE 到G_MAXDOUBLE范围

gsize
typedef unsigned int gsize;
一个无符号整形,用来储存sizeof的结果,与C99的size_t类型类似。
这个类型能足够存储下一个指针的数据。它常常在32为平台上是32位的,在64位平台上是64位的。

gssize
typedef signed int gssize;
一个有符号gsize,与大多数平台的ssize_t类型类似。

goffset
typedef gint64 goffset;
一个有符号的整形,用来作为文件偏移。类似于C99的off64_t
Since: 2.14

FAILED: CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o /usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_ATOMIC_DYN_LINK -DBOOST_DATE_TIME_DYN_LINK -DBOOST_FILESYSTEM_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_REGEX_DYN_LINK -DBOOST_SYSTEM_DYN_LINK -DBOOST_TEST_DYN_LINK -DBOOST_THREAD_DYN_LINK -DLIBBULLET_VERSION=3.05 -DLIBBULLET_VERSION_GT_282 -Dgazebo_aruco_plugin_EXPORTS -I/home/yxz/PX4_Firmware/Tools/simulation/gazebo-classic/sitl_gazebo-classic/include -I/home/yxz/PX4_Firmware/build/px4_sitl_default/build_gazebo-classic -I/usr/include/eigen3/eigen3 -I/usr/include/gazebo-11/gazebo/msgs -I/home/yxz/PX4_Firmware/build/px4_sitl_default/mavlink -I/home/yxz/PX4_Firmware/build/px4_sitl_default/mavlink/mavlink/v2.0 -I/home/yxz/PX4_Firmware/Tools/simulation/gazebo-classic/sitl_gazebo-classic/external/OpticalFlow/include -I/usr/include/gstreamer-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -isystem /usr/include/gazebo-11 -isystem /usr/include/bullet -isystem /usr/include/simbody -isystem /usr/include/sdformat-9.7 -isystem /usr/include/ignition/math6 -isystem /usr/include/OGRE -isystem /usr/include/OGRE/Terrain -isystem /usr/include/OGRE/Paging -isystem /usr/include/ignition/transport8 -isystem /usr/include/ignition/msgs5 -isystem /usr/include/ignition/common3 -isystem /usr/include/ignition/fuel_tools4 -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -isystem /usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++ -isystem /usr/include/eigen3 -isystem /usr/local/include/opencv4 -isystem /usr/include/sdformat-9.7/sdf/.. -isystem /usr/include/ignition/cmake2 -isystem /usr/include/uuid -O2 -g -DNDEBUG -fPIC -Wno-deprecated-declarations -Wno-address-of-packed-member -I/usr/include/uuid -MD -MT CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o -MF CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o.d -o CMakeFiles/gazebo_aruco_plugin.dir/src/gazebo_aruco_plugin.cpp.o -c /home/yxz/PX4_Firmware/Tools/simulation/gazebo-classic/sitl_gazebo-classic/src/gazebo_aruco_plugin.cpp In file included from /home/yxz/PX4_Firmware/Tools/simulation/gazebo-classic/sitl_gazebo-classic/src/gazebo_aruco_plugin.cpp:31: /home/yxz/PX4_Firmware/Tools/simulation/gazebo-classic/sitl_gazebo-classic/include/gazebo_aruco_plugin.h:41: fatal error: opencv2/aruco.hpp: No such file or directory 41 | #include <opencv2/aruco.hpp> | compilation terminated. [72/142] Building CXX object CMakeFile...erface.dir/src/mavlink_interface.cpp.o In file included from /usr/include/boost/smart_ptr/detail/sp_thread_sleep.hpp:22, from /usr/include/boost/smart_ptr/detail/yield_k.hpp:23, from /usr/include/boost/smart_ptr/detail/spinlock_gcc_atomic.hpp:14, from /usr/include/boost/smart_ptr/detail/spinlock.hpp:42, from /usr/include/boost/smart_ptr/detail/spinlock_pool.hpp:25, from /usr/include/boost/smart_ptr/shared_ptr.hpp:29, from /usr/include/boost/shared_ptr.hpp:17, from /usr/include/boost/date_time/time_clock.hpp:17, from /usr/include/boost/date_time/posix_time/posix_time_types.hpp:10, from /usr/include/boost/asio/time_traits.hpp:23, from /usr/include/boost/asio/detail/timer_queue_ptime.hpp:22, from /usr/include/boost/asio/detail/deadline_timer_service.hpp:29, from /usr/include/boost/asio/basic_deadline_timer.hpp:25, from /usr/include/boost/asio.hpp:25, from /home/yxz/PX4_Firmware/Tools/simulation/gazebo-classic/sitl_gazebo-classic/include/mavlink_interface.h:36, from /home/yxz/PX4_Firmware/Tools/simulation/gazebo-classic/sitl_gazebo-classic/src/mavlink_interface.cpp:1: /usr/include/boost/bind.hpp:36:1: note: ‘#pragma message: The practice of declaring the Bind placeholders (_1, _2, ...) in the global namespace is deprecated. Please use <boost/bind/bind.hpp> + using namespace boost::placeholders, or define BOOST_BIND_GLOBAL_PLACEHOLDERS to retain the current behavior.’ 36 | BOOST_PRAGMA_MESSAGE( | ^~~~~~~~~~~~~~~~~~~~ [77/142] Building CXX object CMakeFile...src/gazebo_camera_manager_plugin.cpp.o ninja: build stopped: subcommand failed. [899/903] Linking CXX executable bin/px4 FAILED: external/Stamp/sitl_gazebo-classic/sitl_gazebo-classic-build /home/yxz/PX4_Firmware/build/px4_sitl_default/external/Stamp/sitl_gazebo-classic/sitl_gazebo-classic-build cd /home/yxz/PX4_Firmware/build/px4_sitl_default/build_gazebo-classic && /usr/bin/cmake --build /home/yxz/PX4_Firmware/build/px4_sitl_default/build_gazebo-classic -- -j 7 ninja: build stopped: subcommand failed. make: *** [Makefile:227: px4_sitl_default] Error 1
最新发布
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值