日期:2014-05-16  浏览次数:20629 次

为什么我有些函数和宏定义没法使用?
环境如下:
Linux forhu-debian 3.2.0-4-686-pae #1 SMP Debian 3.2.51-1 i686 GNU/Linux
gcc version 4.7.2 (Debian 4.7.2-5) 


我发现有些函数没法使用,比如说我要使用nanosleep,已经include了time.h了,但是编译器报错如下:
test.c:17:18: error: storage size of ‘req’ isn’t known
test.c:17:22: error: storage size of ‘rem’ isn’t known
test.c:38:3: warning: implicit declaration of function ‘nanosleep’ [-Wimplicit-function-declaration]
make: *** [main.o] Error 1


但是我的代码如下:
  6 #include <time.h>
...
 17         struct timespec req,rem;
 18         req.tv_sec=0;
 19         req.tv_nsec=10000000;
...
 38                 nanosleep(&req,&rem);


等等诸如此类的问题,我看头文件,它需要一个宏定义:
__USE_POSIX199309
还有其他的情况我也碰到:
__USE_BSD
__USE_MISC

请问各位,我碰到这种情况该怎么解决?

------解决方案--------------------
难道楼主用了gcc -std=c89或者 gcc -std=c99或者gcc -ansi
试试改为
gcc -std=gnu99
------解决方案--------------------
引用time.h时这样引用就ok了


#define __need_timespec
#include <time.h>