Joh*_*der 6 c constants c-preprocessor
在一般情况下,是能够更好地定义一些特定的参数(例如(char *) UserIPaddr="192.168.0.5", (int) MAX_BUF=1024通过)#define或constant char */ int?
我读了一些帖子说最好不要在#define可能的时候使用.但是,我从#define源代码的一个例子中看到了开源代码的常见用法:
#define IEEE80211_WLAN_HDR_LEN 24
a_uint8_t *iv = NULL;
a_uint16_t tmp;
a_uint16_t offset = IEEE80211_WLAN_HDR_LEN;
Run Code Online (Sandbox Code Playgroud)
#define可以避免在那里使用,但我想知道为什么在这种情况下使用#define是优选的.我该如何决定何时使用#define?
在C const声明中,不会产生常量表达式,因此如果你需要一个不可能使用的常量表达式const,那么传统的和更常用的方法就是使用它# define.
例如const int,不能用于: