Created
October 7, 2014 05:20
-
-
Save aavina/48fae343b9973c278813 to your computer and use it in GitHub Desktop.
C Compound Literals
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
// 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