linux gcc 先行編譯__linux

來源:互聯網
上載者:User

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.