linux gcc 预编译

来源:互联网 发布:餐饮业进销存软件 编辑:程序博客网 时间:2024/04/28 01:38

linux gcc 预编译
命令:gcc -E test.c -o test.i

 

预编译主要完成以下功能:
1.删除所有的注释“//”和“/**/”;
2.删除所有的“#define”,展开所有的宏定义;
3.处理所有的条件预编译指令;
4.处理“#include”预编译指令,将被包含的文件插入到该预编译指令的位置,这一过程是递归进行的;
5.添加行号和文件名标识;

 

例:

源文件(test.c)如下:

#include <stdio.h>

#define MY_SIZE 1000000

//this is a test
/*this
is
a
test
!
*/

int main(int argc,char* argv[])
{
    char *test=NULL;
    while(1)
    {
        test = NULL;
        test = new char[MY_SIZE];
        if(test == NULL)
        {
            printf("I am wrong/n");
            break;
        }
        printf("a../n");
    }
    printf("I am ok!/n");
    return 0;
}

 

预编译后文件内容(test.i)如下:

。。。//此处略过一大段头文件插入内容

extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__)) ;


extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__));
# 850 "/usr/include/stdio.h" 3 4

# 2 "abc.c" 2
# 13 "abc.c"
int main(int argc,char* argv[])
{
    char *test=((void *)0);
    while(1)
    {
        test = ((void *)0);
        test = new char[1000000];
        if(test == ((void *)0))
        {
            printf("I am wrong/n");
            break;
        }
 printf("a../n");
    }
    printf("I am ok!/n");
    return 0;
}

原创粉丝点击