passing variable number of arguments to a function

Posted on 2013-11-18
Medium Priority
Last Modified: 2013-11-18
Hi Experts,
I want to rename a function from the log4c library for my purpose.  So, I want to have
mylog() instead of the log4c_category_log().  How can I achieve this?

void LOG4C_INLINE mylog(log4c_category_t* catName, int priority, const char *format, ...)
    log4c_category_log(catName, priority, ??????);

Open in new window

Thank you.
Question by:ambuli
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 86

Accepted Solution

jkr earned 1200 total points
ID: 39657133
You could do that using the 'va_*' macros, e.g. like

#include <stdarg.h>

// ...

void LOG4C_INLINE mylog(log4c_category_t* catName, int priority, const char *format, ...)
    static char s_acBuf [ 2048]; // Keep in mind that the buffer size is a caveat!

    va_list args;

    va_start ( args, format);

    vsnprintf ( s_acBuf, sizeof(s_acBuf), format, args);

    log4c_category_log(catName, priority, s_acBuf);

    va_end ( _args);

Open in new window

LVL 84

Assisted Solution

ozo earned 800 total points
ID: 39657232
#include <stdarg.h>
void  log4c_category_log(log4c_category_t* catName, int priority, char *format, va_list args){
  vprintf(format, args);
void LOG4C_INLINE mylog(log4c_category_t* catName, int priority, const char *format, ...)
  va_list args;
  va_start(args, format);
  log4c_category_log(catName, priority, format, args);

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question