![]() |
|
|
|||||||
![]() |
C Programming - wrapper function for ellipsis arg taking functions. |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 sinbad |
|
|
|
|
#2 |
|
Posts: n/a
|
On Nov 3, 12:59*am, sinbad <sinbad.sin...@gmail.com> wrote:
> 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; } robertwessel2@yahoo.com |
|
|
|
#3 |
|
Posts: n/a
|
On Nov 3, 1:49*am, "robertwess...@yahoo.com" <robertwess...@yahoo.com>
wrote: > On Nov 3, 12:59*am, sinbad <sinbad.sin...@gmail.com> wrote: > > > 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; > > > > } And obviously the call in the middle of that was supposed to be: r = vprintf(fmt, pl); robertwessel2@yahoo.com |
|
|
|
#4 |
|
Posts: n/a
|
On 2009-11-03, sinbad <> wrote:
> 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 -- Copyright 2009, all wrongs reversed. Peter Seebach / usenet- http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated! Seebs |
|
|
|
#5 |
|
Posts: n/a
|
sinbad wrote:
> 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. -- Flash Gordon Flash Gordon |
|
|
|
#6 |
|
Posts: n/a
|
Richard Heathfield wrote:
> In <>, Flash Gordon wrote: > >> sinbad wrote: >>> 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. > > Today seems to be typo day. The FAQ is at http://c-faq.com/ Every day is typo day! You are, of course, correct. -- Flash Gordon Flash Gordon |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| small problem replying in Agent 4.2 | GrandpaChuck | Computer Support | 26 | 02-10-2007 04:49 AM |
| Illegal operation | carololine | Computer Support | 12 | 07-14-2006 01:27 PM |
| Disabling Task Mgr. in Windows XP | Bob H | Computer Support | 9 | 02-05-2006 05:02 AM |
| Win XP search function - is there a better way? | Jerry Rivers | Computer Support | 3 | 01-21-2004 07:13 PM |
| Re: Dir listing to html? | wisefool | Computer Support | 2 | 01-20-2004 03:42 AM |