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

  • SEARCH
  • Home
  • 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 6963155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:45:10+00:00 2026-05-27T15:45:10+00:00

I have created a server program, and a certain error has occurred twice where

  • 0

I have created a server program, and a certain error has occurred twice where the function ‘clock()’ has returned a negative value (and crashed the server). Both times it occurred when the program had been running for more than 100 hours, on a Windows 32-bit VPS.

Here’s the setup I have in main.cpp (cut where appropriate):

while (1) {
    Sleep(STEP);

            //execute main code like connection handling, AI, etc.

    //check for clock error
    if (clock() < 0) {
        //error saved here

                //close server
        return 0;
    }
}

That’s it, pretty simple. clock() is used throughout the rest of the program extensively, so when it glitches up like this it causes a lot of problems.

I am wondering, why does it return a negative value, and how can I fix it?

Thanks.

  • 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-05-27T15:45:11+00:00Added an answer on May 27, 2026 at 3:45 pm

    According to Microsoft’s documentation it can return -1 if “the amount of elapsed time is unavailable”. Unfortunately they don’t explain how the time would be unavailable.

    The definition of clock_t is long which is a 32-bit signed value – it can hold 2**31 before it overflows. The value of CLOCKS_PER_SECOND is 1000, so it should be good for 596 hours.

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

Sidebar

Related Questions

I have created a program which allows me to upload images to my server.
I have a server program (works on all three major os systems), created in
I have created a Server, Client kind of program with RMI. But whenever I
I have created a program that prints results on command line. (It is server
I have created a java server, which takes screenshots, resizes them, and sends them
I have created an application server side that will create a pdf of a
I have created a REST server under ASP.NET and I can't figure out the
I have a database that I have created using SQL Server Developer 2008. I
i have created folder on my server (ie finesse)- 'home' in which i have
I have created a discount in commerce server, and linked it with a list

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.