Created
February 26, 2021 10:13
-
-
Save merijn/3ea788047b61ccff221af0837be1ec36 to your computer and use it in GitHub Desktop.
C vs C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char X = 'a'; | |
int main(int argc, char* argv[]) | |
{ | |
(void) argc; | |
(void) argv; | |
struct X { | |
char a[2]; | |
}; | |
if (sizeof(X) == 1) { | |
printf("I am a C program!\n"); | |
} else { | |
printf("I am a C++ program!\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A file that is both correct C11 and correct C++11, but does something different in each language. Compiles warning free with both
gcc -std=c11 -Wall -Wextra -pedantic
andg++ -std=c++11 -Wall -Wextra -pedantic
(well, modulo extension rename, if you use.c
to compile with g++ you'll get a warning about that.