static struct inet_protosw inetsw_array[] =
{
[0] = { /* assignment by index */
.type = SOCK_STREAM, /* assignment by field */
.protocol = IPPROTO_TCP,
.prot = &tcp_prot,
.ops = &inet_stream_ops,
.no_check = 0,
.flags = INET_PROTOSW_PERMANENT |
INET_PROTOSW_ICSK,
},
}
The above code works in C, but not in C++. I think the 2 methods are really nice. How C++ remove it?
PS: It seems field assignment can be accomplished by:
type: SOCK_STREAM
If I remember correctly the
[0]and.typeinitialization designators have been introduced by ISO C99, and since the C++ standard came out in 1998, it didn’t incorporate these features.And also in C++11 it is not possible. The relevant section in the standard is 8.5.1 Aggregates, and all the examples in that section are without designators.