Skip to content

Instantly share code, notes, and snippets.

@aavina
Created October 7, 2014 05:20
Show Gist options
  • Save aavina/48fae343b9973c278813 to your computer and use it in GitHub Desktop.
Save aavina/48fae343b9973c278813 to your computer and use it in GitHub Desktop.
C Compound Literals
// Reference: http://nickdesaulniers.github.io/blog/2013/07/25/designated-initialization-with-pointers-in-c/
struct point a;
a.x = 1;
a.y = 2; // C89 (too verbose)
struct point b = { 3, 4 }; // initializer list (struct member order specific)
struct point c = { .x = 5, .y = 6 }; // designated initializer (non struct member order specific)
struct point d = (struct point) { .x = 7, .y = 8 }; // compound literal (cast + designated initialization)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment