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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:05:00+00:00 2026-06-01T14:05:00+00:00

I’ve always been curious, why does the time(time_t *) function both return a time_t

  • 0

I’ve always been curious, why does the time(time_t *) function both return a time_t, and set the time to the passed in pointer?

Example of returning the time:

time_t myTime = time(NULL);
printf("The time is now %s", ctime(&myTime));

Example of setting the value to the pointer:

time_t myTime;
time(&myTime);
printf("The time is now %s", ctime(&myTime));

I originally thought there would be a performance gain by writing to the memory instead of returning, but if it has to do both, doesn’t that just make it slower?

  • 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-01T14:05:01+00:00Added an answer on June 1, 2026 at 2:05 pm

    There’s no real benefit in the way it’s currently defined.

    I suspect that when the time() function was first defined, it used a type that could not be returned from a function. Very early C implementations didn’t have long int and were not able to return structures from functions. On a system with 16-bit ints, the only way to represent a time would be as a structure or as an array; 16 bits worth of seconds is less than a day.

    UPDATE: My speculation is confirmed, see below.

    So early implementations of time() might have been used something like this (speculation):

    time_t now;
    time(&now);    /* sets now.time_high, now.time_low */
    

    or perhaps:

    int now[2];
    time_t(now);    /* sets now[0], now[1] */
    

    When later C implementations added longer integers and the ability to return structures by value, the ability to return a time_t value from the time() function was added, but the old functionality was kept to avoid breaking existing code.

    I think that if time() were being defined today, it would look more like this:

    time_t time(void);
    

    I haven’t been able to confirm that old implementations of the time() function worked this way (try Googling “time”!), but it makes sense given the history of the language.

    If you pass a null pointer to the time() function, it returns the current time without also storing it in a variable; this avoids some of the performance penalty:

    time_t now = time(NULL);
    

    UPDATE

    Early UNIX sources are available in https://github.com/dspinellis/unix-history-repo

    Checking out the Research-V6 git tag, the man page for the time() system call is in usr/doc/man/man2/time.2. It’s written in an obsolete form of *roff, but here’s my attempt at formatting it. (The implementation, written in PDP-11 assembly and callable from C, is in usr/source/s2/time.s.)

    C didn’t have void functions at that time. Functions without a declared return type would return int by default. It’s not clear to me what the time function would return, but my guess is that it would be the high-order 16-bit word of the 32-bit value. As of the date on the man page, that would have been about 1730, in units of 216 seconds (18h12m16s). Correctly written C code would not have attempted to use the return value.

    TIME 8/5/73

    NAME

    time – get date and time

    SYNOPSIS

    (time = 13.)
    sys time
    
    time(tvec)
    int tvec[2]
    

    DESCRIPTION

    Time returns returns the time since 00:00:00 GMT, Jan. 1, 1970, measured
    in seconds. From as, the high order word is in the r0 register and
    the low order is in r1. From C, the user-supplied vector is filled in.

    SEE ALSO

    date (I), stime (II), ctime (III)

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
I am writing an app with both english and french support. The app requests
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.