Solved

passing variable number of arguments to a function

Posted on 2013-11-18
2
320 Views
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.
0
Comment
Question by:ambuli
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 300 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

0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 200 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);
  va_end(args);
}
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

803 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