里面定义枚举 [英] defines inside enum

查看:163
本文介绍了里面定义枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

里面的Linux内核源代码我看到的是,里面的枚举,有没有也枚举元素的名称相同的定义。在的Linux / rtnetlink.h 例子中,我们有:

Inside linux kernel sources i see that, inside enums, is there also a define with the same name of enum element. Example in linux/rtnetlink.h we have:

enum {
        RTM_BASE        = 16,
#define RTM_BASE        RTM_BASE

        RTM_NEWLINK     = 16,
#define RTM_NEWLINK     RTM_NEWLINK
        RTM_DELLINK,
#define RTM_DELLINK     RTM_DELLINK
...

是什么原因呢?我想不通这是怎么使用的。

What is the reason for this? I can't figure out how this is used.

感谢

推荐答案

另一种猜测:该宏允许在不破坏其他code重命名枚​​举的条目。更改

Another guess: this macro could allow renaming an entry of the enum without breaking other code. Change

enum {
        RTM_BASE        = 16,
#define RTM_BASE        RTM_BASE

enum {
        RTM_BASE_NEW_NEW_NEW        = 16,
#define RTM_BASE        RTM_BASE_NEW_NEW_NEW

一个用户仍旧可以使用 RTM_BASE

A user could still use RTM_BASE.

这篇关于里面定义枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆