Hi,
Why would gcc return, "warning: implicit declaration of function 'sleep'"
?
I do have time.h included.
Thanks for your help
Hi,
Why would gcc return, "warning: implicit declaration of function 'sleep'"
?
I do have time.h included.
Thanks for your help
Because sleep isn't in time.h? It's in unistd.h, on *nix machines.
Wrong header.
http://linux.die.net/man/3/sleep
gg
Is there anything I can use to make a timer... or basically just a delay without that header?
"I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008
"the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010
As cpjust says, I would like to understand why you want to sleep, and yet you do not want to include the correct header-file to achieve that. Either you need to sleep, and thus need to include the correct headerfile (whatever that may be), or you don't call sleep.
Loops can be very tricky for this, as if you want a delay that works the same on a 500MHz P3 with compiled with low optimization level and a 4GHz P4 with compiled with high optimization settings, you need some pretty clever programming. Not to mention than many compilers will optimize empty loops into "nothing".
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
And how would not including a header be an improvement?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
My guess is that this is misdirected attempt to "fancy up" a program, but the students are given a strict list of header files. So the student is trying to solve the problem in a way that doesn't involve including some header that is on the "white-list", and still get the desired delaying effect. I say misdirected, because for the most cases, delays/sleeps are completely meaningless to average users, and annoying to advanced users.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
There are some practical applications for pauses or delays. I am currently writing software that runs diagnostics on a voltage reader. The reader needs to wait approximately 5 seconds before reading the first voltage to allow for any transients to pass.
Speaking of which, I had planned to use a loop to compare start time to current time (using time() from time.h). However this continually uses the CPU, which is something I would like to avoid. I would use the sleep functions from windows.h but I'm running the software I'm writing on a DOS only machine... Is there a sleep equivalent that would work in DOS?
Yes, there is. It's <you'll love this!> called:
The include file is dos.hCode:sleep(N); //where you want N seconds (or what DOS will report as N seconds), of inactivity
That was easy!!
In a single-tasking OS, there is obviously nothing other than looping that will do this job, and as suggested, there is a sleep/delay function that will sleep for a set amount of time.
I'm fully aware of the need to delay or stop an application for some time. However, I also know that there are LOTS of programmers who use this sort of thing unnecessarily in their programs when displaying messages etc. - the delay is often too short for new users, and gets annoying when it takes too long for experienced users. Waiting for the user to press a key is a much better approach in this sort of usage.
Finally, perhaps one of the moderator team could split the new posts on this topic from the old thread.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.