error: expected specifier-qualifier-list before ‘uint8_t’

转载请注明出处: http://blog.csdn.net/zhangyang0402/archive/2010/07/22/5754132.aspx

 

编写一个PF_KEY的测试程序,但一编译就出现了问题。

源代码如下:
#include<stdio.h> #include<sys/socket.h> #include<linux/pfkeyv2.h> int main(void) { int s; s=socket(PF_KEY, SOCK_RAW, PF_KEY_V2); if ( s == -1 ) { perror("create PF_KEY socket failed./n"); return -1; } return 0; }

# gcc test.c -o test
In file included from test.c:3:
/usr/include/linux/pfkeyv2.h:15: error: expected specifier-qualifier-list before ‘uint8_t’
/usr/include/linux/pfkeyv2.h:27: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:33: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:45: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:55: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:64: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:72: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:81: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:97: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:110: error: expected specifier-qualifier-list before ‘uint8_t’
/usr/include/linux/pfkeyv2.h:130: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:142: error: expected specifier-qualifier-list before ‘uint8_t’
/usr/include/linux/pfkeyv2.h:151: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:160: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:167: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:178: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:189: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:203: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:212: error: expected specifier-qualifier-list before ‘uint16_t’
/usr/include/linux/pfkeyv2.h:221: error: expected specifier-qualifier-list before ‘uint16_t’

 

很是奇怪,可能linux/pfkeyv2.h中的uint8, uint16出了问题。grep了一下,发现linux/types.h 和stdint.h中都对uint8_t, uint16_t进行了定义.

linux/types.h
typedef         __u8            uint8_t;
typedef         __u16           uint16_t;
typedef         __u32           uint32_t;
这里只看uint8_t
__u8是在asm/types.h中定义的
typedef unsigned char __u8;

 

stdint.h
typedef unsigned char           uint8_t;
typedef unsigned short int      uint16_t;
#ifndef __uint32_t_defined
typedef unsigned int            uint32_t;
# define __uint32_t_defined
#endif

 

测试结果
#include linux/types.h,依然出现错误,这个是显然的。linux/pfkeyv2.h中include的就是linux/types.h

#include stdint.h,就没问题了。

 

对于这一点,实在有点搞不清楚。有清楚的同仁麻烦告诉一下。

你可能感兴趣的:(socket,测试,File,gcc,include,2010)