zoukankan      html  css  js  c++  java
  • implicit declaration of function ‘typeof’

    我用gcc编译,有std=c99选项。

    出现
    mylist.c:88: warning: implicit declaration of function ‘typeof’
    mylist.c:88: error: expected expression before ‘)’ token
    mylist.c:88: error: expected expression before ‘)’ token
    mylist.c:91: error: expected expression before ‘)’ token
    mylist.c:91: error: expected expression before ‘)’ token

    感觉GCC将typeof当做了函数,而非关键字,而
    list_for_each_entry 的定义为。

    /**
    * list_for_each_entry - iterate over list of given type
    * @pos: the type * to use as a loop counter.
    * @head: the head for your list.
    * @member: the name of the list_struct within the struct.
    */
    #define list_for_each_entry(pos, head, member) \
    for (pos = list_entry((head)->next,typeof(*pos), member); \
    &pos->member != (head); \
    pos
    = list_entry(pos->member.next, typeof(*pos), member))


    mylist第88行的内容
    cat mylist.c |sed -n '87,95p'
           
    printf("traversing the list using list_for_each_entry()\n");
    list_for_each_entry(tmp,
    &mylist.list, list){
    printf(
    "to= %d from= %d\n", tmp->to, tmp->from);
    }
    list_for_each_entry(tmp,
    &mylist.list,list){
    if(tmp->to == 2)
    break;
    }



    这个例子也就是linux内核里面的链表遍历。

    如果将std=c99选项去掉的话,就可以编译通过。

    答案隐藏在C99的编译选项,由于typeof是GCC的扩展,并不在C99标准中,参见gcc的文档

    http://gcc.gnu.org/onlinedocs/gcc/Typeof.html

    The typeof keyword is disabled by default when building with -std=c99
    as it's a GNU extension, make it known that it's an extension by using
    the underscore
    -enclosed variant.

    The underscore
    -encosed keyword is accepted by GCC without requesting
    extensions to the C99 standard,
    while the simpler typeof() keyword
    requires GNU extensions to the C99 standard to be explicitly requested
    (e.g.: by
    using the -fasm option).

    ICC supports the __typeof__ keyword
    as well as typeof.

    如果要启用该扩展,应该用编译选项 std=gnu99即可。

  • 相关阅读:
    docker删除容器再删除镜像
    centOS7安装docker遇到 [Errno 14] curl#35
    设置centos7界面语言为中文
    sublime查看项目代码多少行
    1. 常用及特殊
    7.逆波兰,二叉树三叉树
    6.表单提交,input键盘变搜索,有关自定义属性input操作
    5.字符串的第一次见到的方法
    2.手机上浏览器看控制台的插件
    1. 时间插件
  • 原文地址:https://www.cnblogs.com/westfly/p/2006681.html
Copyright © 2011-2022 走看看