Given this struct:
typedef struct _WLAN_AVAILABLE_NETWORK_LIST {
WLAN_AVAILABLE_NETWORK Network[1];
} *PWLAN_AVAILABLE_NETWORK_LIST;
What does the declaration WLAN_AVAILABLE_NETWORK Network[1]
mean?
Given this struct:
typedef struct _WLAN_AVAILABLE_NETWORK_LIST {
WLAN_AVAILABLE_NETWORK Network[1];
} *PWLAN_AVAILABLE_NETWORK_LIST;
What does the declaration WLAN_AVAILABLE_NETWORK Network[1]
mean?
It looks likely that Network
is intended to serve as a flexible array member. By over-allocating the struct by sizeof(Network) * (n - 1)
bytes, the library and client code can access past the end of the struct as if the array member was n
elements long.
Library code:
PWLAN_AVAILABLE_NETWORK_LIST list = malloc(sizeof(_WLAN_AVAILABLE_NETWORK_LIST)
+ (sizeof(WLAN_AVAILABLE_NETWORK) * (n - 1)));
for (int i = 0; i < n; ++i) {
list->Network[i] = ...;
}
Client code:
for (int i = 0; i < n; ++i) {
do_something(list->Network[i]);
}
typedef struct _WLAN_AVAILABLE_NETWORK_LIST {
declaring a struct named _wlan...list
WLAN_AVAILABLE_NETWORK Network[1];
assumes a struct called WLAN_AVAILABLE_NETWORK
is declared somewhere. It is an array of length 1 (pointless) and called Network.
} *PWLAN_AVAILABLE_NETWORK_LIST;
instantly creates a (pointer) variable of this struct called pwlan...list