【发布时间】:2014-09-01 10:41:47
【问题描述】:
我有以下结构:
typedef struct cxt_simple_socket_address_s
{
int is_ipv6;
cs_inaddr_t ip;
unsigned short ip_port;
} cxt_simple_socket_address_t;
typedef struct cs_inaddr
{
union {
struct in6_addr in6;
struct
{
uint8_t pad[12];
uint32_t in;
};
long long as_longs[2];
};
} cs_inaddr_t;
我想在声明时初始化一个 cxt_simple_socket_address_t 类型的结构:
cxt_simple_socket_address_t any = {.in = INADDR_ANY};
此行无法编译。我尝试了无数其他变体,但我相信我的问题是在匿名联合内的匿名结构中找到 .in。
帮助?
【问题讨论】:
-
您应该依次引用
in。应该是这样的:cxt_simple_socket_address_t any = {.ip = {.<UNION NAME> = {.<STRUCT NAME> = {.in = INADDR_ANY}}}}; -
但是union和struct都是无名的
标签: c struct initialization unions anonymous