I am asking for help to deal with a compile error I have with the sleep() function. The GNU C library help on the internet says to include unistd.h but that does't work. I've opened up unistd.h and it ONLY has an include "IO.h" line in it.
I'm using Bloodshed versoin 4.9.9.2.
The problem happens when I add "sleep(500);" to the simple hello world application:
This may not help much but the unistd.h file is not a standard header file in either C or C++ and the 'sleep' function is not a standard function in either language. You will have to look for an equivalent one that is defined by the operating system. Under Windows for example, include <windows.h> then use "Sleep" with an uppercase first letter (or SleepEx). Under Unix or Linux you would probably use "sleep", but then you would not likely be using Dev-C++...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sleep() worked. I originally tried it in a much more complex set of code, and got an error when I included <windows.h>, but that's obviously another problem. Thanks for the help!
And to the person who assumed I didn't use the forum search, I've got the perfect Author name for you: "cranky_old_goat".
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You have noticed that this forum is searchable? Upper right corner of the web page.
You could searched on sleep and found what you wanted on your own.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-07-07
unistd.h as its name implied (UNIxSTandard.Header) is not really intended for use on Windows. It is provided as a subset to support porting of code.
The difference between the POSIX sleep() function and Windows Sleep() is that sleep() is in seconds, whereas Sleep() is in milliseconds. If you have a lot of POSIX code you do not wish to port (although if that were the case, then sleep() is probably the least of your worries), then you might modify unistd as follows:
include <windows.h>
define sleep(s) Sleep((s)*1000)
Otherwise, just use Sleep() directly.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am asking for help to deal with a compile error I have with the sleep() function. The GNU C library help on the internet says to include unistd.h but that does't work. I've opened up unistd.h and it ONLY has an include "IO.h" line in it.
I'm using Bloodshed versoin 4.9.9.2.
The problem happens when I add "sleep(500);" to the simple hello world application:
include <cstdlib>
include <iostream>
include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
sleep(500);
system("PAUSE");
return EXIT_SUCCESS;
}
============================================
Here's the compile error message:
R:\SW_Dev...\main.cpp In function
int main(int, char**)': R:\SW_Dev\...\main.cpp
sleep' undeclared (first use this function)...
============================================
Here's the contents of unistd.h:
/
* This file is part of the Mingw32 package.
* unistd.h maps (roughly) to io.h
*/
include <io.h>
============================================
The GNU c help page: http://www.gnu.org/software/libc/manual/html_node/Sleeping.html
============================================
Thanks for any help in advance.
Given that you passed the parameter 500 I am guessing that Sleep() is what you wanted all along, the unistd.h sleep() is in seconds, not milliseconds.
This may not help much but the unistd.h file is not a standard header file in either C or C++ and the 'sleep' function is not a standard function in either language. You will have to look for an equivalent one that is defined by the operating system. Under Windows for example, include <windows.h> then use "Sleep" with an uppercase first letter (or SleepEx). Under Unix or Linux you would probably use "sleep", but then you would not likely be using Dev-C++...
Sleep() worked. I originally tried it in a much more complex set of code, and got an error when I included <windows.h>, but that's obviously another problem. Thanks for the help!
And to the person who assumed I didn't use the forum search, I've got the perfect Author name for you: "cranky_old_goat".
You have noticed that this forum is searchable? Upper right corner of the web page.
You could searched on sleep and found what you wanted on your own.
unistd.h as its name implied (UNIxSTandard.Header) is not really intended for use on Windows. It is provided as a subset to support porting of code.
The difference between the POSIX sleep() function and Windows Sleep() is that sleep() is in seconds, whereas Sleep() is in milliseconds. If you have a lot of POSIX code you do not wish to port (although if that were the case, then sleep() is probably the least of your worries), then you might modify unistd as follows:
include <windows.h>
define sleep(s) Sleep((s)*1000)
Otherwise, just use Sleep() directly.
Clifford