Solved

passing variable number of arguments to a function

Posted on 2013-11-18
2
325 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
[X]
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
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.

756 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