Go Back   Velocity Reviews > Newsgroups > C Programming
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

C Programming - wrapper function for ellipsis arg taking functions.

 
Thread Tools Search this Thread
Old 11-03-2009, 06:59 AM   #1
Default wrapper function for ellipsis arg taking functions.


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
  Reply With Quote
Old 11-03-2009, 07:49 AM   #2
robertwessel2@yahoo.com
 
Posts: n/a
Default Re: wrapper function for ellipsis arg taking functions.
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
  Reply With Quote
Old 11-03-2009, 07:52 AM   #3
robertwessel2@yahoo.com
 
Posts: n/a
Default Re: wrapper function for ellipsis arg taking functions.
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
  Reply With Quote
Old 11-03-2009, 07:55 AM   #4
Seebs
 
Posts: n/a
Default Re: wrapper function for ellipsis arg taking functions.
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
  Reply With Quote
Old 11-03-2009, 08:16 AM   #5
Flash Gordon
 
Posts: n/a
Default Re: wrapper function for ellipsis arg taking functions.
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
  Reply With Quote
Old 11-04-2009, 12:26 AM   #6
Flash Gordon
 
Posts: n/a
Default Re: wrapper function for ellipsis arg taking functions.
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46