Multi-argument function - help

U

Ufit

Let's say I want to have a function like this
void func(char *lps, ... (various variables and types) )
{
.....................
printf( lps, (above variables) );
}

How to acces those variables ?
Thank you.

UF
 
L

Larry I Smith

Ufit said:
Let's say I want to have a function like this
void func(char *lps, ... (various variables and types) )
{
.....................
printf( lps, (above variables) );
}

How to acces those variables ?
Thank you.

UF

Check the docs for the vprintf() family of functions.
Also see 'stdarg.h' and read up on va_list, va_start, va_end.

Note the func() will need to be declared:

extern "C" void func( the args )

Larry
 
J

Jesper Madsen

You could also look at boost::any and try to go that way.. Ellipsis function
and c++ does not match..!

--
Jesper Madsen, SAXoTECH

"The truth of the matter is that you always know the right thing to do. The
hard part is doing it"
- General H. Norman Schwartzoff
 
C

cadull

Let's say I want to have a function like this
void func(char *lps, ... (various variables and types) )
{
.....................
printf( lps, (above variables) );
}

How to acces those variables ?

Try the following

va_list args;
va_start(args, lps);
printf(lps, args);
va_end(args);

Regards,
cadull
 
O

Old Wolf

cadull said:
Try the following

va_list args;
va_start(args, lps);
printf(lps, args);
va_end(args);
Better would be vprintf (not printf). Also, lps needs to be
of type 'char const *' .
 
A

Abecedarian

Ufit said:
Let's say I want to have a function like this
void func(char *lps, ... (various variables and types) )
{
.....................
printf( lps, (above variables) );
}

How to acces those variables ?

Write overloaded functions for each combination of the 'various'
argument types. Write printf function calls according to the argument
types.

::A::
 

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
474,202
Messages
2,571,057
Members
47,667
Latest member
DaniloB294

Latest Threads

Top