这些#define在枚举中的目的是什么? [英] What is the purpose of a these #define within an enum?
本文介绍了这些#define在枚举中的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在linux头文件/usr/include/dirent.h中找到了此代码:
I found this code in the linux headers, /usr/include/dirent.h:
enum
{
DT_UNKNOWN = 0,
# define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1,
# define DT_FIFO DT_FIFO
DT_CHR = 2,
# define DT_CHR DT_CHR
DT_DIR = 4,
# define DT_DIR DT_DIR
DT_BLK = 6,
# define DT_BLK DT_BLK
DT_REG = 8,
# define DT_REG DT_REG
DT_LNK = 10,
# define DT_LNK DT_LNK
DT_SOCK = 12,
# define DT_SOCK DT_SOCK
DT_WHT = 14
# define DT_WHT DT_WHT
};
此构造用于什么? -为什么用相同的字符串定义某些内容,然后将其编译为int值?
What is this construct for? - why define something with an identical string, which will then compile to the int value?
推荐答案
我的猜测是,然后其他代码可以检查是否已使用#ifdef定义了这些枚举值中的一个(或多个).
My guess is that some other code can then check if one of (or more of) these enum values have been defined using #ifdef.
这篇关于这些#define在枚举中的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文