__cplusplus在編譯時區分c/c++

代碼:this

#include <stdio.h>io


int main(int argc, char* argv[]){test

#ifdef __cplusplusgcc

        printf("this is cpp\n");gc

#endifdi

        printf("Hello, world!\n");vi

        return 0;return

}printf

運行:

ongonginging@ongonginging-virtual-machine:~$ gcc test.c 

ongonginging@ongonginging-virtual-machine:~$ ./a.out 

Hello, world!

ongonginging@ongonginging-virtual-machine:~$ g++ test.c 

ongonginging@ongonginging-virtual-machine:~$ ./a.out 

this is cpp

Hello, world!

ongonginging@ongonginging-virtual-machine:~$ 

相關文章
相關標籤/搜索