question about implicit declaration error

M

michael

Hi All,

I have the following:

#define MAX_SLEEP_TIME 1000
#include <unistd.h>

void do_sleep(){
unsigned int random;
while(TRUE){
srand(time(NULL)%getpid());
random = rand()%MAX_SLEEP_TIME;
if(random != 0) break;
}
usleep(random);
}

when I compile I get a warning that says "implicit declaration of usleep". I
thought usleep was declared in <unistd.h>

What have I got wrong and how can I fix it?

Thanks for your help

Michael
 
A

Azazel

Hi All,

I have the following:

#define MAX_SLEEP_TIME 1000
#include <unistd.h>

void do_sleep(){
unsigned int random;
while(TRUE){
srand(time(NULL)%getpid());
random = rand()%MAX_SLEEP_TIME;
if(random != 0) break;
}
usleep(random);
}

when I compile I get a warning that says "implicit declaration of usleep". I
thought usleep was declared in <unistd.h>

What have I got wrong and how can I fix it?

This would be better asked on comp.unix.progammer.

Check the man-page for the function. For example, under Linux, the
synopsis is:

#define _XOPEN_SOURCE 500 /* Or: #define _BSD_SOURCE */
#include <unistd.h>

int usleep(useconds_t usec);

Az.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,591
Members
45,103
Latest member
VinaykumarnNevatia
Top