wrapper function for ellipsis arg taking functions.

S

sinbad

hi,

how to write a wrapper function (NOT macro) for printf() like
functions.
i want to write a wrapper for printf(),i am stuck at "how to pass
variable args to the printf() from the wrapper function. I know how to
do it with macros. But i want this to be done using wrapper as a
function.
Anyone please shed some light.

thanks
 
R

robertwessel2

hi,

how to write a wrapper function (NOT macro) for printf() like
functions.
i want to write a wrapper for printf(),i am stuck at "how to pass
variable args to the printf() from the wrapper function. I know how to
do it with macros. But i want this to be done using wrapper as a
function.


You can't exactly. But if you have a function like vprintf() instead,
which takes a va_list instead of a "...", you can do something like:

int myprintf(char *fmt, ...)
{
va_list pl;
int r;
va_start(pl, fmt);
r = vprintf(fmt, ap);
va_end(pl);
return r;
}
 
R

robertwessel2

You can't exactly.  But if you have a function like vprintf() instead,
which takes a va_list instead of a "...", you can do something like:

int myprintf(char *fmt, ...)
{
   va_list pl;
   int r;
   va_start(pl, fmt);
   r = vprintf(fmt, ap);
   va_end(pl);
   return r;



}


And obviously the call in the middle of that was supposed to be:

r = vprintf(fmt, pl);
 
S

Seebs

hi,

how to write a wrapper function (NOT macro) for printf() like
functions.
i want to write a wrapper for printf(),i am stuck at "how to pass
variable args to the printf() from the wrapper function. I know how to
do it with macros. But i want this to be done using wrapper as a
function.
Anyone please shed some light.

vprintf()

-s
 
F

Flash Gordon

sinbad said:
hi,

how to write a wrapper function (NOT macro) for printf() like
functions.
i want to write a wrapper for printf(),i am stuck at "how to pass
variable args to the printf() from the wrapper function. I know how to
do it with macros. But i want this to be done using wrapper as a
function.
Anyone please shed some light.

I'm sure this is in the comp.lang.c FAQ at http://f-faq.com/ but, in any
case, look up vprintf.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top