Tech Support Guy banner
Status
Not open for further replies.
1 - 8 of 8 Posts

· Registered
Joined
·
51 Posts
Discussion Starter · #1 ·
I have a lot of sleep(1) function calls in my program.
sleep(unsigned int) is obsolete, according to the Borland C++ compiler. It gives me the following warning:

Warning W8053 ar1.cpp 26: 'sleep(unsigned int)' is obsolete in function main()

So, OK, it's just a warning, so I keep using sleep(). But now I have too many of these function calls, and I get this message after all the warnings:

Error E2228 ar1.cpp 357: Too many error or warning messages in function DE()

(DE is the last function out of about 6 so far, but later it'll be about 40-50 functions.)

So now it won't compile due to the error of having too many warnings.

Is there a newer function I can use to pause the program for a certain amount of seconds?

Thanks,
Michael
 

· Registered
Joined
·
2,452 Posts
It means call the function and pass into it the value of the delay you want in milliseconds in the form of a data type DWORD, which is a macro substitution for an "unsigned long" 32bit integer value. You could declare a variable of this type and give it the value of delay you require, or a value dependant on calculation for that matter then just call the Sleep() function and pass that variable to it.

DWORD dwMilliseconds = 1000; // create DWORD type variable to hold delay time in milliseconds
Sleep ( dwMilliseconds ); // Sleep for that number of msecs, note bold!

try something like that.

Not sure of the '#include's you will need off the top of my head, #include<winbase.h> springs to mind but coderitr would be better advising that if you don't know yourself. :)
 

· Registered
Joined
·
3,089 Posts
#include <windows.h>

Will get you everything you need. Thanks for the excellent follow-up explanation AlbertB. I copied my post from the MSDN library article on the function without realizing that I may have neede to provide more.

You can call the function without a separate variable declaration ( saving a whopping 4 bytes of memory :D ) by the following:

Sleep( 1000 ); // sleep for 1 second
 

· Registered
Joined
·
2,452 Posts
Sorry, I was asleep(). ;)
 
1 - 8 of 8 Posts
Status
Not open for further replies.
Top