Solved

passing variable number of arguments to a function

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

710 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