Can anybody tell how to write a program which when compiled with gcc prints c , and with g++ prints c++?
#ifdef __cplusplus
printf("c++\n");
#else
printf("c\n");
#endif
You may run into issues if your file extension isn't right.
Something like this:
#if __cplusplus
printf("c++");
#else
printf("c");
#endif
Unless you're compiling with g++ -x c which it will still print C even though compiled with g++. That's a gotcha.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With