LINUX C中用define定义可变参数的宏
一般在调试打印Debug信息的时候, 需要可变参数的宏. 从C99开始可以使编译器标准支持可变参数宏(variadic macros), 另外GCC也支持可变参数宏, 但是两种在细节上可能存在区别.
1. __VA_ARGS__
__VA_ARGS__ 将 "..." 传递给宏 . 如
#define debug(format, ...) fprintf(stderr, format, __VA_ARGS__)
2. GCC的复杂宏
GCC使用一种不同的语法,从而可以给可变参数一个名字,如同其它参数一样.
#define debug(format, args...) fprintf (stderr, format, args)
这和第一条的宏例子是完全一样的,但是这么写可读性更强并且更容易进行描述.
3. ##__VA_ARGS__
上面两个定义的宏,如果出现 debug("A Message")的时候,由于宏展开后有个多余的逗号,所以将导致编译错误.
为了解决这个问题,CPP 使用一个特殊的"##"操作,格式如下:
#define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
这里,如果可变参数被忽略或为空,"##"操作将使预处理器(preprocessor)去除掉它前面的那个逗号.
相关文档:
/*
kmalloc can apply 128KB memory only. This func support any continous memory allocate more than 2MB.
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kallsyms.h>
#define KMEM_PAGES &nb ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
1 进程管理相关代码
1.1 thread_info结构,在文件<asm/thread_info.h>中定义
struct thread_info {
struct task_struct *task;
struct exec ......
1 cron
以下,是ctontab的格式:
分<>时<>日<>月<>星期<>要运行的命令
其中<>表示空格。
这里有c r o n t a b文件条目的一些例子:
30 21* * * /apps/bin/cleanup.sh
上面的例子表示每晚的2 1 : 3 0运行/ a p p s / b i n目录下的c l e a n u p . s h。
45 4 1,10,22 * ......
Linux下C语言编程基础(Makefile)
2005-01-18 10:28:23 来自:赛迪网
假设我们有下面这样的一个程序,源代码如下:
/* main.c */
#include "mytool1.h"
#include "mytool2.h"
int main(int argc,char **argv)
{
mytool1_print("hello");
mytool2_print(&q ......