Jump to content
  • Advertisement
Sign in to follow this  
adam_o

Breaking out of time

This topic is 4308 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, I have been trying to create an abort sequence for a the function below, but I don't think that it's supposed to work the way I'm doing it. Is the way I have put it below wrong, or is there a better way to put this? All help is appreciated. adam-o
#include <time.h>
#include <stdio.h>
using namespace std;

void wait();

int main()
{
	wait(5.0);
	return 0;
}

void wait (double time)
{
	clock_t endwait;
	endwait = clock () + (time) * CLOCKS_PER_SEC;
	while (clock() < endwait) 
	{
		/* if conditions are right, abort this function */
	}
}

Share this post


Link to post
Share on other sites
Advertisement
I'm not entirely sure what you're asking. Are you asking 1) how to abort wait() inside the loop, or 2) if the wait() function is alright as you have coded it?

If #2, it's fine except that it will probably be hogging CPU as it loops during the wait function, and it would generally be better to use the OS function instead of wait(). See Sleep() in Win32 or sleep()/usleep() in Linux (granularity in seconds and milliseconds respectively).

Share this post


Link to post
Share on other sites
I think he just wants to know how to return from the function.

If that's the case, then the "break" keyword will break from a loop, and the "return" keyword will return from a function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!