2

muslgcc 使用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);
}
...
...
4

1 回答 1

2

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

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

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

于 2020-03-06T20:01:53.950 回答