Skip to content

Instantly share code, notes, and snippets.

@merijn
Created Feb 26, 2021
Embed
What would you like to do?
C vs C++
#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;
}
@merijn

This comment has been minimized.

Copy link
Owner Author

@merijn merijn commented Feb 26, 2021

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 and g++ -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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment