Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 要根据参数大小调用不同的宏吗_C_Macros_C Preprocessor - Fatal编程技术网

C 要根据参数大小调用不同的宏吗

C 要根据参数大小调用不同的宏吗,c,macros,c-preprocessor,C,Macros,C Preprocessor,我的故事是我想从不同大小的整数集合一个静态字节数组 因此,我有三个宏作为 #define CONV_BYTE(x) (uint8_t)(x) #define CONV_WORD(x) (uint16_t)(x) & 0xff, (uint16_t)(x) >> 8 & 0xff #define CONV_LONG(x) (uint32_t)(x) & 0xff, (uint32_t)(x) >> 8 &am

我的故事是我想从不同大小的整数集合一个静态字节数组

因此,我有三个宏作为

#define CONV_BYTE(x)        (uint8_t)(x)
#define CONV_WORD(x)        (uint16_t)(x) & 0xff, (uint16_t)(x) >> 8 & 0xff
#define CONV_LONG(x)        (uint32_t)(x) & 0xff, (uint32_t)(x) >> 8 & 0xff, \
        (uint32_t)(x) >> 16 & 0xff, (uint32_t)(x) >> 24 & 0xff
它们被用作

const uint8_t const _name[] = {CONV_BYTE(byte_arg), CONV_WORD(word_arg), CONV_LONG(long_arg)};
有没有办法为所有长度类型的参数设置一个宏,根据参数的大小选择相应的宏


据我所知,sizeof()似乎是一条死胡同。有什么诀窍吗?

编译器如何知道您需要哪种输入类型?请注意,如果正确启用,宏将生成转换警告。@Leandros我认为您不能在
\u Generic
表达式部分中使用
。(我不是100%确定)@Leandros谢谢你的建议,据我所知,\你的泛型词只在函数指针之类的值上,而不是表达式上?@tanxiyu-Nope,
\你的泛型
适用于任何表达式(逗号运算符除外)。编译器如何知道你想要哪种输入类型?请注意,如果正确启用,宏将生成转换警告。@Leandros我认为您不能在
\u Generic
表达式部分中使用
。(我不是100%确定)@Leandros谢谢你的建议,据我所知,_泛型词仅用于函数指针之类的值,而不用于表达式?@tanxiyu-Nope,
_泛型
适用于任何表达式(逗号运算符除外)。