Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Timer

Name: Anonymous 2008-02-16 7:34

Hi /prog/,

I know intermediate level Visual Basic (yes i know it's AIDS) and am learning C. I'm just wondering if there's a way to implement timer like functionality in C and if there is how to go about it.

Name: Anonymous 2008-02-16 7:39

Use a for loop with a sufficiently large number.

Name: Anonymous 2008-02-16 7:50

sleep()

Name: Anonymous 2008-02-16 8:07

No, in ISO C you cannot have that.
You can, however use sleep() and nanosleep() in POSIX.1(b).
(and there are other techniques, using select(), or if you are aware of the kernel running, syscall())

Name: Anonymous 2008-02-16 8:26

>>2
DON'T HELP HIM!

Name: Anonymous 2008-02-16 8:28

>>2
that's one of the worst ideas I've ever heard.

Name: Anonymous 2008-02-16 8:56

>>4
On Windows:
#include <windows.h>

On UNIX/BSD/etc.:
#include <sys/types.h>
#include <sys/time.h>
#include <unistd.h>

And finally:
timeval waittime;
waittime.tv_sec = SecondstoWait;
waittime.tv_usec = MicroSecondsToWait;
select( 0, NULL, NULL, NULL, &waittime );

But in most cases the system-timer has got only Millisecond-resolution.
I'm pretty sure the last sentence is wrong. Sorry for that.
Btw.: select( ) is a socket-function.

Name: Anonymous 2008-02-16 8:58

Depends on what you want to do, but while(true) in combination with break usually works for me.

Name: >>4 2008-02-16 9:10

>>7
Btw.: select( ) is a socket-function.
lol faggot.
select() is not a "socket function".
select() waits for a number of file descriptors to change status.
man 2 select.

Name: Anonymous 2008-02-16 9:17

>>1
On which platform? The C library doesn't define any timer routines.

Name: Anonymous 2008-02-16 9:24

>>10
You mean the C standard. not library.

Name: Anonymous 2008-02-16 9:36

signal(SIGALRM, dostuff);
setitimer(ITIMER_REAL, ...);

Name: Anonymous 2008-02-16 9:38

>>6
Welcome to /prog/

Name: Anonymous 2008-02-16 10:03

>>6
jmp_buf env;
if (_setjmp(env) < when)
    _longjmp(env, time(NULL));

Name: Anonymous 2008-02-16 10:28

>>14
minus the underscore, faggot.
setjmp/longjmp are ISO C in <setjmp.h>

Name: Anonymous 2008-02-16 16:08

The underscore is correct, faggot.

Name: Anonymous 2008-02-16 16:31

>>11
Yes, quite.

Name: Anonymous 2011-02-04 12:12

Name: Anonymous 2013-01-19 23:26

/prog/ will be spammed continuously until further notice. we apologize for any inconvenience this may cause.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List