Two compilation problems encountered

Time:2021-1-19

Recently, I encountered two compilation problems, which took a lot of effort.

container_ Of question

I defined container in one place_ Of macro, but repeated compilation errors
Macro is defined as follows:

#define container_of(ptr, type, member) ({\
    const typeof( ((type *)0)->member ) *__mptr = (ptr);\
    (type *)( (void *) ( (char *)__mptr - offsetof(type,member) ) );})

The error is as follows:

error: expected declaration specifiers or '...' before '(' token

At the beginning, Google couldn’t connect. The information found by Baidu said that there was something wrong with the. H file, but I carefully checked my file, and there was no problem.
Later, Google was able to search and found the answer on the familiar stackoverflow
Link: https://stackoverflow.com/questions/27029643/define-error-expected-declaration-specifiers-or-before-token
The solution is to add two underscores in front of typeof

#define container_of(ptr, type, member) ({\
    const __typeof( ((type *)0)->member ) *__mptr = (ptr);\
    (type *)( (void *) ( (char *)__mptr - offsetof(type,member) ) );})

strtok_ R problem

I use strsok_ K to split the string, also containsHeader file, I didn’t expect to report errors all the time

implicit declaration of function ‘strtok_r’

After searching, the solution is the same as above, just add two underscores in front, that is to use__ strtok_r