Using this knowledge, I made a program that outputs a different message based on the compiler you are using. There is probably a more standard way of doing this, but here is my way:
#include <stdio.h>
int main()
{
if (sizeof('k')==sizeof(int)) { //Everyone knows k is the best letter
printf("You used a C compiler.\n");
} else if (sizeof('k')==sizeof(char)) {
printf("You used a C++ Compiler.\n");
} else {
printf("What compiler are you using?\n");
}
return 0;
}
It is even smart enough to tell you when it doesn't know what you are using.Here is output from my terminal:
alex@Cheese:~/Programs$ gcc test.c -o test alex@Cheese:~/Programs$ ./test You used a C compiler. alex@Cheese:~/Programs$ g++ test.c -o test alex@Cheese:~/Programs$ ./test You used a C++ Compiler.
Edited by Guest, 25 October 2009 - 12:57 PM.


Sign In
Create Account


Back to top









