What is the proper #include for the function 'sleep()'? What is the proper #include for the function 'sleep()'? c c

What is the proper #include for the function 'sleep()'?


The sleep man page says it is declared in <unistd.h>.

Synopsis:

#include <unistd.h>

unsigned int sleep(unsigned int seconds);


sleep is a non-standard function.

  • On UNIX, you shall include <unistd.h>.
  • On MS-Windows, Sleep is rather from <windows.h>.

In every case, check the documentation.


this is what I use for a cross-platform code:

#ifdef _WIN32#include <Windows.h>#else#include <unistd.h>#endifint main(){  pollingDelay = 100  //do stuff  //sleep:  #ifdef _WIN32  Sleep(pollingDelay);  #else  usleep(pollingDelay*1000);  /* sleep for 100 milliSeconds */  #endif  //do stuff again  return 0;}