Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c

gcc

macros

musl

gcc throws following error with 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);
}
...
...
like image 849
Necktwi Avatar asked Sep 16 '25 01:09

Necktwi


1 Answers

Without seeing any more of the code, my best guess is that the program has not included stddef.h to get offsetof, and GCC is (wrongly; this really really should be a hard error) treating it as an implicitly declared function rather than a macro.

If this only happens on musl, not glibc or some other system you've tried it on, it's probably that the other libc is mildly violating namespace by implicitly including stddef.h from some other header.

Note that you can make the implicit function thing an error with -Werror=implicit-function-declaration to catch errors like this.

like image 118
R.. GitHub STOP HELPING ICE Avatar answered Sep 19 '25 14:09

R.. GitHub STOP HELPING ICE