"error: expected expression before struct" at macro argument to `offsetof` inside a macro function with musl

"error: expected expression before struct" at macro argument to `offsetof` inside a macro function with musl

gcc 使用 musl libc

抛出以下错误
device_achat.c:192:29: error: expected expression before ‘struct’
  return container_of(_iocb, struct ffs_request, iocb);
                             ^~~~~~
device_achat.c:52:45: note: in definition of macro ‘container_of’
         (type *)( (char *)__mptr - offsetof(type,member) );})
                                             ^~~~

device_achat.c

...
...
#define container_of(ptr, type, member) ({                      \
        const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
        (type *)( (char *)__mptr - offsetof(type,member) );})
...
...
/* Use container_of() to get ffs_request from iocb */
static inline struct ffs_request *to_ffs_request(struct iocb *_iocb)
{
    return container_of(_iocb, struct ffs_request, iocb);
}
...
...

没有看到更多的代码,我最好的猜测是该程序没有包含 stddef.h 来获得 offsetof,而 GCC 是(错误的;这真的 真的 应该是一个硬错误)将其视为隐式声明的函数而不是宏。

如果这只发生在 musl 上,而不是 glibc 或您尝试过的其他系统,则可能是其他 libc 通过隐式包含来自其他 header 的 stddef.h 轻微违反命名空间].

请注意,您可以使用 -Werror=implicit-function-declaration 将隐式函数设为错误以捕获此类错误。