Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
C compound literals
/*
* Compile with:
* gcc compound-literals.c -Wall -Wextra -std=c99 -Werror
*/
#include <stdio.h>
#include <stdlib.h>
struct bin_tree {
int value;
struct bin_tree *left;
struct bin_tree *right;
};
#define NODE(V, L, R) &(struct bin_tree){V, L, R}
int main ()
{
const struct bin_tree *tree = \
NODE(4,
NODE(2, NULL, NULL),
NODE(7,
NODE(5, NULL, NULL),
NULL));
printf("tree->value = %d\n", tree->value);
printf("tree->value = %d\n", tree->left->value);
printf("tree->value = %d\n", tree->right->value);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.