Created
November 15, 2011 05:30
-
-
Save dcoles/1366250 to your computer and use it in GitHub Desktop.
C99 features that don't work in 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
/** | |
* C99 features that don't work in C++ | |
* | |
* Written in 2011 by David Coles <coles.david@gmail.com> | |
* | |
* To the extent possible under law, the author(s) have dedicated all copyright and related and | |
* neighboring rights to this software to the public domain worldwide. | |
* This software is distributed without any warranty. | |
*/ | |
#include <stdio.h> | |
// Comment this out if you want to compile with a C++ compiler | |
#define USE_C99 | |
struct person { | |
const char* name; | |
int age; | |
}; | |
const struct person me = {"David", 42}; | |
#ifdef USE_C99 | |
// These C99 features are invalid in C++ | |
const struct person me2 = {.name="David", .age=42}; | |
const int abc[255] = { [42]=1, [43]=2 }; | |
#endif | |
int main(int argc, char* argv[]) { | |
printf("My name is %s and I'm %d\n", me.name, me.age); | |
#ifdef USE_C99 | |
printf("My name is %s and I'm %d\n", me2.name, me2.age); | |
printf("Some good numbers are %d, %d and %d\n", abc[0], abc[42], abc[43]); | |
#endif | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment