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;
}