Created
February 18, 2016 07:09
-
-
Save danellis/7446dd500ea23ea01995 to your computer and use it in GitHub Desktop.
C anonymous inner struct initialization
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
#include <stdio.h> | |
typedef struct { | |
// Required | |
const char *fq_name[3]; | |
// Optional | |
const char *display_name; | |
const char *href; | |
const char *name; | |
const char *uuid; | |
struct { | |
const char *fq_name[3]; | |
struct { | |
struct { | |
struct { | |
const char *ip_prefix; | |
int ip_prefix_length; | |
} subnet; | |
struct { | |
const char *start; | |
const char *end; | |
} allocation_pools [1]; | |
const char *default_gateway; | |
const char *dns_server_address; | |
} subnets[1]; | |
} attributes; | |
} network_ipams[1]; | |
} VirtualNetwork; | |
int main() { | |
VirtualNetwork vnet = { | |
.fq_name = {"domain", "project", "test-net"}, | |
.display_name = "Test network", | |
.href = NULL, | |
.name = NULL, | |
.uuid = NULL, | |
.network_ipams = { | |
{ | |
.fq_name = {"domain", "project", "ipam"}, | |
.attributes = { | |
{ | |
{ | |
.subnet = {"10.1.0.0", 16}, | |
.allocation_pools = {{"10.1.0.2", "10.1.255.254"}}, | |
.default_gateway = "10.1.0.1", | |
.dns_server_address = "10.1.0.2" | |
} | |
} | |
} | |
} | |
} | |
}; | |
printf( | |
"First IP address = %s/%i\n", | |
vnet.network_ipams[0].attributes.subnets[0].allocation_pools[0].start, | |
vnet.network_ipams[0].attributes.subnets[0].subnet.ip_prefix_length | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment