This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: va__list and pointers
- From: Brian Dessent <brian at dessent dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Wed, 14 Sep 2005 16:51:30 -0700
- Subject: Re: va__list and pointers
- References: <1126740895.4625.21.camel@localhost>
"Fco. J" wrote:
> > unsigned char *t_ctime()
> > {
> > time_t tim;
> > tim=time(NULL);
> > sleep(1);
> > return(ctime(&tim));
> > }
The behavior you are seeing has nothing to do with gcc or printf or
va_args or anything else. It's because ctime() returns a static
buffer. (Read its documentation.) Because of this you must always use
the result of a call to ctime() before calling it again because each
call will overwrite that same buffer. Try ctime_r() instead.
You should really find a general C language list or newsgroup for these
questions, because this is not gcc-specific.
Brian