Why are #define values ​​inside an enumeration?

I came across something unusual for me while reading one of the Linux headers <linux/rtnetlink.h>:

/* RTnetlink multicast groups */
enum rtnetlink_groups {
        RTNLGRP_NONE,
#define RTNLGRP_NONE            RTNLGRP_NONE
        RTNLGRP_LINK,
#define RTNLGRP_LINK            RTNLGRP_LINK
        RTNLGRP_NOTIFY,
#define RTNLGRP_NOTIFY          RTNLGRP_NOTIFY
        RTNLGRP_NEIGH,
#define RTNLGRP_NEIGH           RTNLGRP_NEIGH
        RTNLGRP_TC,
#define RTNLGRP_TC              RTNLGRP_TC
        RTNLGRP_IPV4_IFADDR,
#define RTNLGRP_IPV4_IFADDR     RTNLGRP_IPV4_IFADDR
/* ... etc, pattern continues ... */
};

It's hard for me to understand the reason for the appearance of macros or what difference they will make. What purpose does this serve?

+4
source share
1 answer

It makes constants visible to the preprocessor. You can use #ifdefto check if a certain constant is available.

+6
source

Source: https://habr.com/ru/post/1655661/


All Articles