Solved

passing variable number of arguments to a function

Posted on 2013-11-18
2
307 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now