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: "stdarg.h", va_start(), with gcc.






Hi,

I am trying to create a program on Solaris with GCC.  I has to use
va_start().  The way I use "va_start" in my program as follows:

#include <stdarg.h>

trace(char *fmt, ...)
{
        va_list ap;
        if (tracing)
        {
                va_start(ap, fmt);
                fprintf(stderr, "TRACE: [%s] ", get_timestamp());
                vfprintf(stderr, va_arg(ap, char*), ap);
                fprintf(stderr, "\n");
                va_end(ap);
        }
}

In calling function,
....

trace("Creating socket on port %i", config_getPort());
....

I got an error "Segmentation Fault(coredump)" on that call to function
"trace".  But the program works if I compile it on Aix with cc compiler
(not gcc).

Can anyone advise what was wrong in my code?  Please show me the correct
way to use "va_start".

Many thanks in advance!


Jeffrey Yuan
SSA Global
214-775-5946
jeffrey.yuan@ssaglobal.com

Learn why 13,000 businesses worldwide rely on SSA Global to extend ERP
across all their enterprise processes -- from supplier to employee to
customer.
Get started by visiting www.ssaglobal.com


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