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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:38:15+00:00 2026-06-06T14:38:15+00:00

the prototype of the function ctime is char *ctime(const time_t *timep); As we can

  • 0

the prototype of the function ctime is

char *ctime(const time_t *timep);

As we can see, it return a string. but, where the sting be contained?

and why we shouldn’t free the string’s memory

This is sample code will get a lots of error message

char *p;
p = ctime(...);
...
free(p);

*** glibc detected *** ./a.out: free(): invalid pointer: 0x00007f0b365b4e60 ***

  • 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-06T14:38:16+00:00Added an answer on June 6, 2026 at 2:38 pm

    It returns a pointer to a static buffer, and must not be free()d. From man ctime:

    The four functions asctime(), ctime(), gmtime() and localtime() return a pointer to static data and hence are not thread-safe.

    The C99 standard, section 7.23.3.2 The ctime function states that calling ctime(timer) function is equivalent to asctime(localtime(timer)), and the asctime() implementation (as illustrated in the same document) is equivalent to:

    char *asctime(const struct tm *timeptr)
    {
        static const char wday_name[7][3] = {
            "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
        };
    
        static const char mon_name[12][3] = {
            "Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
        };
    
        static char result[26];
        sprintf(result,
                "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
                wday_name[timeptr->tm_wday],
                mon_name[timeptr->tm_mon],
                timeptr->tm_mday, timeptr->tm_hour,
                timeptr->tm_min, timeptr->tm_sec,
                1900 + timeptr->tm_year);
    
        return result;
    }
    

    The argument passed to free() must be a pointer returned by a call to malloc(), calloc() or realloc() only, otherwise the behaviour is undefined.

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

Sidebar

Related Questions

Function.prototype.method = function (name, func) { this.prototype[name] = func; return this; }; Stolen from
I have some (library API, so I can't change the function prototype) function which
I've got the following function prototype: bool key_pressed(enum key key) const; I documented it
I have the function prototype here: extern C void __stdcall__declspec(dllexport) ReturnPulse(double*,double*,double*,double*,double*); I need to
Assume the following function prototype: void *function(int arg) . Is that a pointer to
From: http://ejohn.org/apps/learn/#2 Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object =
I wonder if someone could be kind enough to explain the function.prototype thingie (thingie!!??)
I'm learning C and I saw in a book that a function prototype has
TL;DR: Adding any non-built-in functions to Array.prototype AND Function.prototype will cause the IE8 native
QTableWidget::setItemPrototype says following. The table widget will use the item prototype clone function when

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.