4

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);
}
...
...
walnut
  • 21,629
  • 4
  • 23
  • 59
Necktwi
  • 2,483
  • 7
  • 39
  • 62

1 Answers1

4

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.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • the complete code is at https://github.com/kopasiak/simple_usb_chat/tree/master/device_asynch_chat – Necktwi Mar 07 '20 at 05:08
  • `make CFLAGS="-Werror=implicit-function-declaration"` didn't throw the error on glibc – Necktwi Mar 07 '20 at 05:21
  • @Necktwi: Indeed, because some header is implicitly pulling in `stddef.h` and the `offsetof` macro definition is therefore present. Adding that option would only help identify the problem when it's not defined (as on musl, since you didn't include anything that would define it). – R.. GitHub STOP HELPING ICE Mar 07 '20 at 15:17
  • Well, `#include ` gave a clean compile! – Necktwi Mar 07 '20 at 19:19