Is it possible with macros make cross platform Sleep code? For example
#ifdef LINUX
#include
#endif
#ifdef WINDOWS
Yes there is. What you do is wrap the different system sleeps calls in your own function as well as the include statements like below:
#ifdef LINUX
#include <unistd.h>
#endif
#ifdef WINDOWS
#include <windows.h>
#endif
void mySleep(int sleepMs)
{
#ifdef LINUX
usleep(sleepMs * 1000); // usleep takes sleep time in us (1 millionth of a second)
#endif
#ifdef WINDOWS
Sleep(sleepMs);
#endif
}
Then your code calls mySleep
to sleep rather than making direct system calls.