我使用的是Big Nerd Ranch的书Objective-C Programming,它首先让我们在前几章用C语言编写。在我创建的一个程序中,我使用了睡眠功能。在书中,它告诉我将#include <stdlib.h>
放在#include <stdio.h>
部分之下。这应该是为了摆脱这样的警告:“'sleep‘函数的隐式声明在C99中无效”。但是由于某种原因,在我放置了#include <stdlib.h>
之后,警告并没有消失。这个问题并没有阻止程序正常运行,但我只是好奇我需要使用哪种#include
!
发布于 2014-04-19 01:34:34
这是我用于跨平台代码的代码:
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
int main()
{
pollingDelay = 100
//do stuff
//sleep:
#ifdef _WIN32
Sleep(pollingDelay);
#else
usleep(pollingDelay*1000); /* sleep for 100 milliSeconds */
#endif
//do stuff again
return 0;
}
发布于 2013-02-12 02:04:00
sleep(3)
在unistd.h
中,而不是stdlib.h
中。在命令行中输入man 3 sleep
来确认您的机器,但我假设您是在Mac上,因为您正在学习Objective-C,并且在Mac上,您需要unistd.h
。
https://stackoverflow.com/questions/14818084
复制相似问题