BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

va_arg question

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
py
Guest





PostPosted: Fri Nov 25, 2005 3:39 pm    Post subject: va_arg question Reply with quote



Hello

I want to pass va argss of a function as va argss of another function. how
can I do that ?

example:

int func_1(...) { /*...*/ }
int func_2(...) { /*...*/ }

int func(bool x;...)
{
if (x)
func_1(/*the va args*/);
else
func_2(/*the va args*/)
}

What must be the args when calling func_1 and func_2 ?

Thank you

s.pierre-yves (s.py)


Back to top
Liz Albin
Guest





PostPosted: Fri Nov 25, 2005 4:29 pm    Post subject: Re: va_arg question Reply with quote



On Fri, 25 Nov 2005 16:39:15 +0100, py wrote:

Quote:
What must be the args when calling func_1 and func_2 ?

How about looking up va_args in the help. There are examples of just
what you're asking for
--
liz

Back to top
py
Guest





PostPosted: Fri Nov 25, 2005 5:19 pm    Post subject: Re: va_arg question Reply with quote



Thank you for the try, Liz but sounds like you missed my question. How about
looking up the whole message before answering ?
I obviously started with the help, and the vc help too, and search on the
web etc. And finally I posted here.

copy/past from borland help :

#include <stdio.h>
#include <stdarg.h>

/* calculate sum of a 0 terminated list */
void sum(char *msg, ...)
{
int total = 0;
va_list ap;
int arg;
va_start(ap, msg);
while ((arg = va_arg(ap,int)) != 0) {
total += arg;
}
printf(msg, total);
va_end(ap);
}

int main(void) {
sum("The total of 1+2+3+4 is %dn", 1,2,3,4,0);
return 0;
}

Ok, nothing I don't know (in fact there is really few things which I do not
know on c++ or pascal)

My question is: having already va args in a function, how can I pass them to
another function ?
(note the 'already' word above)

A more complete sample is here:

int my_sprintf(char *buffer, const char *format[, argument, ...])
{
if (is_std_format_specifiers(format))
return sprintf(buffer,format[,arguments,...]); // <<<<< HERE, how
can I pass the whole 'argument(s)' to sprintf
else {
/* process the format string by hand */
};
}

Note that watching the implementation of va_start,va_arg etc, the only
solution i've found is by using 'naked' functions. what I m searching for is
a portable way, if any exists.

s.pierre-yves (s.py)

"Liz Albin" 1oqjajo307nq0$.1or5i9y0bntlp.dlg (AT) 40tude (DOT) net...
Quote:
On Fri, 25 Nov 2005 16:39:15 +0100, py wrote:

What must be the args when calling func_1 and func_2 ?

How about looking up va_args in the help. There are examples of just
what you're asking for
--
liz





Back to top
Chris Uzdavinis (TeamB)
Guest





PostPosted: Fri Nov 25, 2005 5:32 pm    Post subject: Re: va_arg question Reply with quote

"py" <spy200205 (AT) hotmail (DOT) com> writes:

Quote:
Thank you for the try, Liz but sounds like you missed my
question. How about looking up the whole message before answering ?
I obviously started with the help, and the vc help too, and search
on the web etc. And finally I posted here.

Take a look at the source to AnsiString.
($BCB6sourcevcldstring.cpp, I think)

It has a member function called sprintf, which forwards its calls into
the internal vsprintf function, I believe. That may be an example you
can use. (I don't have it handy to check for myself, and don't do
this sort of thing often enough to memorize it.)

--
Chris (TeamB);

Back to top
Liz Albin
Guest





PostPosted: Fri Nov 25, 2005 6:11 pm    Post subject: Re: va_arg question Reply with quote

On Fri, 25 Nov 2005 18:19:56 +0100, py wrote:

Quote:
(note the 'already' word above)

Please try to be slightly less condescending.

I presumed you knew enough to check the most common use of va_args:
vsprintf. Here's the example from the online help:

you get the arglist in a function, and pass that along.

int vspf(char *fmt, ...)
{
va_list argptr;
int cnt;

va_start(argptr, fmt);
cnt = vsprintf(buffer, fmt, argptr);
va_end(argptr);

return(cnt);
}



--
liz

Back to top
py
Guest





PostPosted: Fri Nov 25, 2005 8:39 pm    Post subject: Re: va_arg question Reply with quote


"Liz Albin" <lizalbinNotThis (AT) yahoo (DOT) com> a écrit dans le message de news:
o8x0xoybiyzo$.nj65kkodszwp$.dlg (AT) 40tude (DOT) net...
Quote:
On Fri, 25 Nov 2005 18:19:56 +0100, py wrote:

(note the 'already' word above)

Please try to be slightly less condescending.


Yes ! I was (intentionnally) condescending, and even agitator, bc u was
first - law of retaliation, I never fire first.
Yes I neglected search on the bdn, bc I'm not accustomed to find there what
I need. This time it was an error ok, but who never do ?

Liz Albin wrote:

Quote:

How about looking up va_args in the help. There are examples of just
what you're asking for
--
liz

but now peace and thanks for your last post :)

s.pierre-yves (s.py)




Back to top
Liz Albin
Guest





PostPosted: Sat Nov 26, 2005 1:42 pm    Post subject: Re: va_arg question Reply with quote

On Fri, 25 Nov 2005 21:39:11 +0100, py wrote:

Quote:
Yes ! I was (intentionnally) condescending, and even agitator, bc u was
first - law of retaliation, I never fire first.

Actually, I wasn't . I was terse. Had you looked through examples,
and remembered printf and its cousins, you might have found a solution
more quickly.

Quote:
Yes I neglected search on the bdn, bc I'm not accustomed to find there what
I need. This time it was an error ok, but who never do ?

I'm not sure why you're bringing up bdn, which is not whence the
example came.

Do yourself a favor, write conservatively, read forgivingly. Also,
don't quote entire posts when you respond, trim to the relevent bits.

Follow-up set to bpot.
--
liz

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Mon Nov 28, 2005 6:29 pm    Post subject: Re: va_arg question Reply with quote


"py" <spy200205 (AT) hotmail (DOT) com> wrote


Quote:
My question is: having already va args in a function,
how can I pass them to another function ?

You pass in the va_list like you do any other function parameter value.

Quote:
if (is_std_format_specifiers(format))
return sprintf(buffer,format[,arguments,...]);
how can I pass the whole 'argument(s)' to sprintf

You cannot. You need to use vsprintf() instead of sprintf(). vsprintf()
accepts a va_list as a parameter:

int my_sprintf(char *buffer, const char *format, ...)
{
va_list ap;
va_start(ap, format);
int ret;

if( is_std_format_specifiers(format) )
ret = vsprintf(buffer, format, ap);
else
{
// process the format string by hand ...
// ret = ...;
}

va_end(ap);
return ret;
}


Gambit



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.