#ifndef SLEEP_H

#ifndef SLEEP_H
#define SLEEP_H

#if defined(unix) || defined(__unix__) || defined(__unix)
#include
#define sleepSeconds(a) sleep(a);
#elif defined(_WIN32)
#include
#define sleepSeconds(a) Sleep(a * 1000);
#else
#include
#define sleepSeconds(a) assert(0 && "sleepSeconds() not implemented for this OS!");
#endif

#endif // SLEEP_H

>C lang has no standard wait function
Is this the proper way of writing a cross-platform sleep function?

Attached: 1661662953949070.gif (640x640, 1.08M)

frankie booba

>Is this the proper way of writing a cross-platform sleep function?
No. Move the platform specific includes into a C file and make sleepSeconds a function not a macro.

#if defined(unix) || defined(__unix__) || defined(__unix)
#include
void sleepSeconds(int a) {
sleep(a);
}
#elif defined(_WIN32)
#include
void sleepSeconds(int a) {
Sleep(a * 1000);
}
#else
#include
void sleepSeconds(a) {
assert(0 && "sleepSeconds() not implemented for this OS!");
}
#endif

So this is the proper way?

bait

Nah, I'm just bad at being a cnile

SLEEP(3) Linux Programmer's Manual SLEEP(3)
RETURN VALUE
Zero if the requested time has elapsed, or the number of seconds left to sleep, if the call
was interrupted by a signal handler.

>Linux
I need it to work on other OSs too. And I don't need anything complicated anyways.

>>C lang has no standard wait function
When you get to "real" programming, you realise how not useful a sleep function like that really is.

I'm writing a program that "presses" a button on a webpage automatically after a set amount of wait time. So in this situation it's needed.

write for POSIX and if you need to suck Bill Gates cock install mingw

Just use select().

>suck Bill Gates cock install mingw
mingw is a pain in the ass to install and use

select isn't standard either dumdum

But it does??
#include
#include

int main()
{
setvbuf(stdout, NULL, _IONBF, 0);
struct timespec ts = { .tv_sec = 1};

for (int i = 1; i

Attached: 1658214900726070.png (802x1048, 497.68K)

>threads.h
>C11

Attached: f82.jpg (600x689, 50.29K)

no, you're supposed to have 2 seperate files for windows and unix, which will contain the implementations
then you put a function prototype in the header like this
void sleepSeconds(int);

then you link the unix code if it's the unix makefile, or link the windows code if it's the windows build script

Thanks for the info, user!
I'll go learn cross-platform makefiles then

GCC and Clang both default to C11 and even the Linux kernel has moved onto it.

You are reinforcing his point.

Learn CMake.

epic xdd

>writes a C program that can be implemented in 5 lines of javascript
Peak Any Forums moment.

I want to run it 24/7 on my phone so I don't want the heavy burden of Node