为什么要使用GLib函数? [英] Why use GLib functions?

查看:69
本文介绍了为什么要使用GLib函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C和GTK +中进行编程时,为什么更好地使用g_strdup_printfg_freeg_strcmp0等...和其他GLib函数呢?

While programming in C and GTK+, why is it "better" to use g_strdup_printf, g_free, g_strcmp0 etc... and fellow GLib functions?

推荐答案

通常,GLib的用途是实用程序和可移植性库.这些本身就是考虑使用它的原因.

In general, GLib's purpose is a utility and portability library. Those in itself are reasons to consider using it.

您提到的所有特定功能都在其C标准库变体的基础上提供了一些额外的功能:

The specific functions you mention all offer something extra on top of their C standard library variants:

  • g_strdup_printf类似于sprintf,但是实际上为您分配了缓冲区,并避免了您猜测缓冲区应该有多大的猜测. (返回值应为g_free d.)
  • g_freefree类似,但是会检查NULL指针.
  • g_strcmp0类似于strcmp,但是将NULL指针视为空字符串,因此将其放在前面.
  • g_strdup_printf is like sprintf, but actually allocates the buffer for you and saves you the guesswork of how large the buffer should be. (The return value should be g_free'd.)
  • g_free is like free, but checks for a NULL-pointer.
  • g_strcmp0 is like strcmp, but treats a NULL-pointer like an empty string, and thus sorts it in front.

这篇关于为什么要使用GLib函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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