Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8383517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:10:55+00:00 2026-06-09T17:10:55+00:00

Question regarding clock tick count generated by clock() from <ctime> . (Usage of clock()

  • 0

Question regarding clock tick count generated by clock() from <ctime>. (Usage of clock() is covered in other questions)

On my system clock_t is an alias for long whose max value according to my compiler’s <climits> is 2147483647.

clock_t delay = clock_t(10) * CLOCKS_PER_SEC;
clock_t start = clock();
while(clock() - start < delay); //Note Semi-colon here makes this null statement
std::cout << clock();

Running this I get roughly 10060. Which is consistent with CLOCKS_PER_SEC being #defined (for my system) as 1000.

So if there’s 1000 CLOCKS_PER_SEC then 2147483647 / 1000 = 2147483.647 seconds, which works out to be roughly 24-25 days.

I’m not sure if it’s actually defined behavior by C++, but I note that common behavior of exceeding the long limit is to wrap to the negative end.

For example,

long m = long(2147483647);
std::cout << ++m << std::endl;

Would output: -2147483648

So suppose the program had been running for a long time before initializing start, and start happened to be initialized to 2147483647 (max possible long value).

At this point, I’d assume we’d start wrapping on values returned by clock() so getting values such as -2147482649 as we are approaching 2147483647 again.
So now my original code would probably take a very long time to complete the loop, much longer than the delay intended.

Is the the actual behavior? Should this style pause only be used for delays less than a certain amount? Is there some other check that ought be made to make this “safe”?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T17:10:56+00:00Added an answer on June 9, 2026 at 5:10 pm

    What happens when you overflow a signed integral type is implementation
    defined, and could be a signal. And yes, this means that clock() can
    only be used for a fixed length of time after the start of your process,
    and probably only then if the implementation ensures that the first call
    will always return 0 (the case on all implementations I know of).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I asked this question regarding a strange behaviour from a GridView control in ASP.Net
I realize there are other questions on SO regarding animations and progressbars, but they
I have a question regarding launching an external application from an asp.net website. Now
I recently posted a question regarding moving multiple images and got some advice from
Question regarding GtkBuilder. When we unref builder pointer does it destroys all the screens/widgets
Question regarding fluent nHibernate table mappings: Apparently I was under the mistaken impression, that
Quick question regarding memory management in C++ If I do the following operation: pointer
simple question regarding property value inheritance in UserControls. If i create a UserControl, it
Quick question regarding delegateEvents in a View - can we specify multiple event bindings
i have a question regarding the AsyncTask class in android, and why it is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.