Skip to content

Instantly share code, notes, and snippets.



Created Nov 15, 2011
What would you like to do?
C99 features that don't work in C++
* C99 features that don't work in C++
* Written in 2011 by David Coles <>
* 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 };
int main(int argc, char* argv[]) {
printf("My name is %s and I'm %d\n",, me.age);
#ifdef USE_C99
printf("My name is %s and I'm %d\n",, me2.age);
printf("Some good numbers are %d, %d and %d\n", abc[0], abc[42], abc[43]);
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment