This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: va__list and pointers


"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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]