Chinaunix首页 | 论坛 | 博客
  • 博客访问: 248684
  • 博文数量: 16
  • 博客积分: 345
  • 博客等级: 一等列兵
  • 技术积分: 611
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-19 00:16
文章分类

全部博文(16)

文章存档

2013年(2)

2012年(14)

我的朋友

分类:

2012-12-16 00:38:47

使用gcc的-E -P选项展开源代码中的宏- -

                                      

原文出处:

内容简介:演示如何将C代码中的宏展开。
使用工具:gcc
测试平台:cygwin
任务描述:文件header1.h中描述了宏的声明,文件header2.h中使用到了这些宏,现在需要将文件header2.h中的宏展开,生成文件shit.h。
关键字:gcc cygwin macro #define expand precompile

文件1"header1.h",内容如下:
#define A1 10
#define A2 0x0A
#define A3 (A1+1)

文件2"header2.h",内容如下:
#include "header1.h"

typedef struct st_Shit
{
  int  m1[A1];
  int  m2[A2];
  char m3[A3];
}t_Shit;

使用如下命令:
gcc -E -P  -< header2.h > shit.h

header2.h中的宏展开之后,生成shit.h文件,内容如下:
typedef struct st_Shit
{
 int  m1[10 ];
 int  m2[0x0A ];
 char m3[(10 +1) ];
}t_Shit;

如果不使用-P开关,命令如下:
gcc -E -< header2.h > shit.h

header2.h中的宏展开之后,生成shit.h文件,内容如下:
# 1 ""
# 1 "header1.h" 1

# 1 "" 2

typedef struct st_Shit
{
 int  m1[10 ];
 int  m2[0x0A ];
 char m3[(10 +1) ];
}t_Shit;

可见,-P选项能够屏蔽掉这些垃圾内容

阅读(8243) | 评论(0) | 转发(0) |
0

上一篇:统计代码行数

下一篇:C++ UML Tips

给主人留下些什么吧!~~