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 6910779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:51:30+00:00 2026-05-27T08:51:30+00:00

Searched for answer for this but couldn’t find anything. The closest I could find

  • 0

Searched for answer for this but couldn’t find anything. The closest I could find was
difftime returning 0 when there is clearly a difference Which has a great explanation that has to do with how the arguments are pushed onto the stack and what the format expects, but I think my issue is different:

I’ve made as simple of an example as possible. Suppose I have the following code in C:

time_t starttime = time(NULL)
somefunction();
time_t newtime = time(NULL)

fprintf(stderr, "starttime %f and difftime %f\n", starttime, difftime(newtime, starttime));
fprintf(stderr, "difftime %f and starttime %f\n", difftime(newtime, starttime), starttime);
return 0;

And somefunction is some function that runs for 1 or 2 seconds. The output I get for this is:

starttime 2.000000 and difftime 0.000000
difftime 2.000000 and starttime 0.000000

I don’t even know where to begin my question. Why is it when I swap the order, the outputted values are still the same? Furthermore, why is one of the values 0? This is the same whether I use %f, %d, %lu, %llu, etc. Is there a stack-argument explanation to this? What is fprintf really doing internally?

Thank you. I’ve wasted too much of my life trying to debug this and I really would appreciate your help!

  • 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-27T08:51:31+00:00Added an answer on May 27, 2026 at 8:51 am

    starttime is a time_t, but you’re to print it with a %f, which expects a double. Evidently, on your platform, time_t is some integer type instead.

    Likely, your platform’s calling convention for variable-argument-list functions like fprintf() passes floating point arguments in a different location from integer arguments.

    The difftime() function is likely returning 2.0, which is being passed in the first floating-point argument location, which is why the first %f prints a 2.0 in both cases. The second floating-point argument location appears to contain a zero, so the second %f prints a zero in both cases. The time_t argument is being placed in a different location that isn’t being examined by the fprintf() code at all.

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

Sidebar

Related Questions

I searched a lot but couldn't find a answer for this question: Is there
I've Googled, I've searched, but I couldn't find an answer to this. I've written
I searched StackOverflow but couldn't find the answer to this question. Suppose I have
I've searched for this, but couldn't find an answer and for whatever reason I
I've binged a lot for this stuff, but couldn't find direct ANSWER, I've searched
I searched around but couldn't find an answer. I'm not sure if this is
I searched for the answer to this question but couldn't find any good. Maybe
I searched a bit, but couldn't find an answer to this (probably very simple)
I searched for this a lot but couldn't find the answer. Tomcat documentation on
I searched google but couldn't find an answer to this rather simple question. I

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.