zoukankan      html  css  js  c++  java
  • 遇到的两个编译问题

    最近遇到两个编译问题,着实费了一番功夫。

    container_of 问题

    我在一个地方,定义了container_of的宏,却屡次出现编译错误
    宏定义如下:

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

    报错如下:

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

    一开始谷歌连不上,用百度查出来的资料都是说.h文件包含有问题,不过我仔细检查了我的文件包含,并没有问题。
    后来谷歌可以了,搜索后在熟悉的stackoverflow上找到了答案
    链接:https://stackoverflow.com/questions/27029643/define-error-expected-declaration-specifiers-or-before-token
    解决方式就是在typeof前面也加两个下划线,修改后的代码:

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

    strtok_r问题

    我使用strsok_k来分割字符串,也包含了<string.h>头文件,没想到一直报错

    implicit declaration of function ‘strtok_r’
    

    经搜索,解决方法与上面的相同,在前面加两个下划线即可,即使用__strtok_r

  • 相关阅读:
    A
    博弈论
    K
    快速幂
    基数排序
    计数排序
    KMP求字符串最小循环节
    二分图多重匹配
    hdu2818行列匹配+排序
    二分图行列匹配与最大匹配必须边
  • 原文地址:https://www.cnblogs.com/shenlinken/p/12741687.html
Copyright © 2011-2022 走看看