我在QEMU v2.9.0(最新的标记版本)中做了一些工作,在{QEMU_Root}/include/qemu/bswap.h
文件中,他们根据endianess生成了一些函数。
代码如下所示:
#define CPU_CONVERT(endian, size, type)\
static inline type endian ## size ## _to_cpu(type v)\
{\
return glue(endian, _bswap)(v, size);\
}\
\
static inline type cpu_to_ ## endian ## size(type v)\
{\
return glue(endian, _bswap)(v, size);\
}\
\
static inline void endian ## size ## _to_cpus(type *p)\
{\
glue(endian, _bswaps)(p, size);\
}\
\
static inline void cpu_to_ ## endian ## size ## s(type *p)\
{\
glue(endian, _bswaps)(p, size);\
}\
CPU_CONVERT(be, 16, uint16_t)
CPU_CONVERT(be, 32, uint32_t)
CPU_CONVERT(be, 64, uint64_t)
CPU_CONVERT(le, 16, uint16_t)
CPU_CONVERT(le, 32, uint32_t)
CPU_CONVERT(le, 64, uint64_t)
我不需要触摸此代码,但由于某种原因,它无法正确编译。我一直收到错误:
/home/xubuntu/Development/QEMU/Source/v2.9.0/include/qemu/bswap.h:162:13: error: ‘be’ undeclared (first use in this function)
CPU_CONVERT(be, 16, uint16_t)
^
/home/xubuntu/Development/QEMU/Source/v2.9.0/include/qemu/bswap.h:144:17: note: in definition of macro ‘CPU_CONVERT’
return glue(endian, _bswap)(v, size);\
^
/home/xubuntu/Development/QEMU/Source/v2.9.0/include/qemu/bswap.h:162:13: note: each undeclared identifier is reported only once for each function it appears in
CPU_CONVERT(be, 16, uint16_t)
^
/home/xubuntu/Development/QEMU/Source/v2.9.0/include/qemu/bswap.h:144:17: note: in definition of macro ‘CPU_CONVERT’
return glue(endian, _bswap)(v, size);\
"le"
出现同样的错误。什么可能会导致这样的事情发生?
修改
在评论中,有一些关于glue
函数调用实际上是什么的混淆。它也是{QEMU_Root}/include/qemu/compiler.h
#define xglue(x, y) x ## y
#define glue(x, y) xglue(x, y)