__cplusplus在编译时区分c/c++

代码:

#include <stdio.h>


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

#ifdef __cplusplus

        printf("this is cpp\n");

#endif

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

        return 0;

}

运行:

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:~$ 


你可能感兴趣的:(__cplusplus在编译时区分c/c++)