1/
Qsort 使用方法:
/* Define struct bb_applet applets[] */
#include "../include/applets.h"
enum { NUM_APPLETS = ARRAY_SIZE(applets) };
static int cmp_name(const void *a, const void *b)
{
const struct bb_applet *aa = a;
const struct bb_applet *bb = b;
return strcmp(aa->name, bb->name);
}
qsort(applets, NUM_APPLETS, sizeof(applets[0]), cmp_name);
/* 莫名技巧? */
bz_stream bzs; /* it's small */
#define strm (&bzs)
char *iobuf;
#define rbuf iobuf
2/
头文件中
#ifndef _WMI_H
#define _WMI_H
….
#endif /* _WMI_H */
3/
内部函数不会被其他源文件函数调用的话,就定义为static静态函数,并且不用声明在头文件。
全局变量也是如此!
一般内部函数写在文件较前面,而外部函数写在最下面
4/
常用控制台程序提示帮助函数
static void
usage (const char *progname)
{
char *foo;
foo = g_path_get_basename (progname);
fprintf (stdout, "%s %s\n\n%s\n%s\n\n",
_("Usage:"),
foo,
_("This program is a component of NetworkManager (http://projects.gnome.org/NetworkManager)."),
_("It is not intended for command-line interaction but instead runs in the GNOME desktop environment."));
g_free (foo);
}
for (i = 1; i < argc; i++) {
if (!strcmp (argv[i], "--help")) {
usage (argv[0]);
exit (0);
}
}
5/
Switch case 与if else
条件判断多于6个才用switch,不过还是要具体看是什么判断
6/
不同条件/状态的参数模式设置
enum {
OPT_c = (1 << 0),
OPT_d = (1 << 1),
OPT_e = (1 << 2),
OPT_f = (1 << 3),
OPT_l = (1 << 4),
OPT_a = (1 << 5),
OPT_M = (1 << 6),
OPT_p = (1 << 7) * ENABLE_FEATURE_PIDFILE,
};