相关疑难解决方法(0)

为什么在C中定义具有相同名称和内容的宏?

我正在研究if_link.hLinux内核头文件,它包含这个枚举:

enum {
        IFLA_UNSPEC,
        IFLA_ADDRESS,
        IFLA_BROADCAST,
        IFLA_IFNAME,
        IFLA_MTU,
        IFLA_LINK,
        IFLA_QDISC,
        IFLA_STATS,
        IFLA_COST,
#define IFLA_COST IFLA_COST
        IFLA_PRIORITY,
#define IFLA_PRIORITY IFLA_PRIORITY
        IFLA_MASTER,
#define IFLA_MASTER IFLA_MASTER
....
}
Run Code Online (Sandbox Code Playgroud)

定义看起来没用; 他们的目的是什么?为什么只有一些项目定义了?

c macros c-preprocessor

15
推荐指数
1
解决办法
578
查看次数

为什么主编译器对stdint.h使用typedef,而对stdbool.h使用#define?

我只是注意到gcc和clang似乎都对stdint.h使用typedef,而对stdbool.h使用#define.

例如:clang的stdint.h

 #ifdef __INT8_TYPE__
 #ifndef __int8_t_defined  /* glibc sys/types.h also defines int8_t*/
 typedef __INT8_TYPE__ int8_t;
 #endif /* __int8_t_defined */
 typedef __UINT8_TYPE__ uint8_t;
 # define __int_least8_t int8_t
 # define __uint_least8_t uint8_t
 #endif /* __INT8_TYPE__ */
Run Code Online (Sandbox Code Playgroud)

clang的stdbool.h

#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#elif defined(__GNUC__) && !defined(__STRICT_ANSI__)
/* Define _Bool, bool, false, true as a GNU extension. */
#define _Bool bool
#define bool  bool
#define false false
#define true  true
#endif
Run Code Online (Sandbox Code Playgroud)

为什么不呢typedef _Bool bool;? …

c typedef include language-lawyer c-preprocessor

12
推荐指数
1
解决办法
1144
查看次数

标签 统计

c ×2

c-preprocessor ×2

include ×1

language-lawyer ×1

macros ×1

typedef ×1