On Friday 03 July 2015 19:13:02 Marek Lindner wrote:
@@ -299,10 +299,10 @@ struct batadv_orig_node {
- (= orig node announces a tvlv of type BATADV_TVLV_MCAST)
*/ enum batadv_orig_capabilities {
- BATADV_ORIG_CAPA_HAS_DAT = BIT(0),
- BATADV_ORIG_CAPA_HAS_NC = BIT(1),
- BATADV_ORIG_CAPA_HAS_TT = BIT(2),
- BATADV_ORIG_CAPA_HAS_MCAST = BIT(3),
- BATADV_ORIG_CAPA_HAS_DAT,
- BATADV_ORIG_CAPA_HAS_NC,
- BATADV_ORIG_CAPA_HAS_TT,
- BATADV_ORIG_CAPA_HAS_MCAST,
};
Do we need an initialization of the first element or can we rely on the compiler to start with 0 ?
Just discussed this with Marek on IRC. We came to the conclusion that ANSI C "3.5.2.2 Enumeration specifiers" is enforcing a 0 as first entry (when not specified otherwise):
If the first enumerator has no = , the value of its enumeration constant is 0. Each subsequent enumerator with no = defines its enumeration constant as the value of the constant expression obtained by adding 1 to the value of the previous enumeration constant.
But the code should maybe cleaned up to either use "= 0" everywhere or nowhere in the internal representations.
Places where = 0 is used:
* net/batman-adv/bat_iv_ogm.c:enum batadv_dup_status * net/batman-adv/main.h:enum batadv_uev_action (maybe not internal?) * net/batman-adv/main.h:enum batadv_uev_type (maybe not internal?) * net/batman-adv/types.h:enum batadv_dhcp_recipient
Not used:
* net/batman-adv/gateway_common.h:enum batadv_gw_modes * net/batman-adv/gateway_common.h:enum batadv_bandwidth_units * net/batman-adv/hard-interface.h:enum batadv_hard_if_state * net/batman-adv/hard-interface.h:enum batadv_hard_if_cleanup * net/batman-adv/main.h:enum batadv_mesh_state * net/batman-adv/multicast.h:enum batadv_forw_mode * net/batman-adv/types.h:enum batadv_counters
I don't count packet.h because this is clearly not internal and the packet definitions should not be accidentally changed just because the enum constant order is changed.
Kind regards, Sven