implicit declaration of function ‘typeof’
2011-04-06 12:48
1546 查看
我用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 的定义为。
mylist第88行的内容
cat mylist.c |sed -n '87,95p'
这个例子也就是linux内核里面的链表遍历。
如果将std=c99选项去掉的话,就可以编译通过。
答案隐藏在C99的编译选项,由于typeof是GCC的扩展,并不在C99标准中,参见gcc的文档
http://gcc.gnu.org/onlinedocs/gcc/Typeof.html
如果要启用该扩展,应该用编译选项 std=gnu99即可。
出现
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即可。
相关文章推荐
- 关于"implicit declaration of function 'gettimeofday' is invalid in c99"的解决
- 关于 implicit declaration of function --Which should not record for myself
- C语言中,函数不声明也能使用,但会出现warning: implicit declaration of function
- Xcode解决“Implicit declaration of function 'XXX' is invalid in C99” 警告或报错
- implicit declaration of function 'i2c_transfer'
- 出现implicit declaration of function 'h1940_latch_control错误的解决方法
- 解决warning:implicit declaration of function 'Xil_Out32' [-Wimplicit-function-declaration]
- drivers/mfd/ezx-pcap.c:214: error: implicit declaration of function 'irq_to_gpio'
- xCode中去除“Implicit declaration of function 'sysctl' is invalid in C99” 警告
- implicit declaration of function 'class_device_create'
- Implicit declaration of function 'SecItemExport' is invalid in C99
- 关于 implicit declaration of function --Which should not record for myself
- C系列: 关于implicit declaration of function的warning
- implicit declaration of function '...' 的warning
- error : implicit declaration of function CC_MD5 is invalid in C99
- implicit declaration of function 'asprintf' 警告的解决
- 一些关于ARM驱动的问题 make menuconfig && implicit declaration of function
- error:implicit declaration of function "irq_to_gpio"
- 解决:implicit declaration of function 警告
- error: implicit declaration of function 'gettimeofday'