--------------------------------------------------------------------------------
Hi,
I was wondering if we can create a va_list by adding objects in the
va_list instead of passing in the parameter preceding first optional
argument? In another words, I want to create a va_list in a similar
manner as creating an array.
The reason is I want to use FormatMessage() in my program where it
takes in a va_list as an argument, but the objects that I would like
to pass in with the va_list is not in the form of a parameter
argument.
I tried doing the following but obviously it won't work, but I have no
idea:
va_list temp;
va_arg(temp, long) = value1;
va_arg(temp, long) = value2;
ANy help would be greatly appreciated,
Thanks,
Peter 6 3669
Peter wrote: I tried doing the following but obviously it won't work, but I have no idea:
va_list temp; va_arg(temp, long) = value1; va_arg(temp, long) = value2;
ANy help would be greatly appreciated,
Write a variadic function that calls the function you're interested in.
void wrapper(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
FormatMessage(fmt, ap); // whatever you need here
va_end(ap);
}
Now call wrapper from the spot where you know what your arguments are:
wrapper(fmt, value1, value2);
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com)
Peter wrote: I was wondering if we can create a va_list by adding objects in the va_list instead of passing in the parameter preceding first optional argument? In another words, I want to create a va_list in a similar manner as creating an array.
The reason is I want to use FormatMessage() in my program where it takes in a va_list as an argument, but the objects that I would like to pass in with the va_list is not in the form of a parameter argument.
I tried doing the following but obviously it won't work, but I have no idea:
va_list temp; va_arg(temp, long) = value1; va_arg(temp, long) = value2;
ANy help would be greatly appreciated,
I'd create a proxy function with ellipsis in the argument list and then
in it I'd implement the forming of va_list using va_args which I'd after
creating it passed to whatever function I need:
int MyFormatMessage(other_arguments, int lastone, ...)
{
va_list lst;
va_start(lst, lastone);
FormatMessage(blahblahblah, lst);
va_end(lst);
}
That's the way to create your own "printf"-like functions that use vprintf
to actually print.
V
Thank you very much for your suggestions. I think that's a good idea.
The only thing is that I was wondering if I can create something that
is more generic. Because I don't want to just create a single wrapper
function for a single call in the program.
The problem is, the parameters' type can be different types (ex, long,
int ....etc ). Does anybody know how I can write the wrapper Pete
suggested into something that takes in like generic parameters? Is that
even possible?
Thanks a lot,
Peter
Actually, for the two wrappers you guys suggested, would it work if the
parameter is int or long? Doesn't FormatMessage takes only
null-terminated strings? So even if we have a va_list but the arguments
in the va_list are long/int, so it still won't work right? Does that
mean I still need to convert my long variables to char* right? How can
I do that in a "better" way than just using casting>? ks****@gmail.com wrote: Actually, for the two wrappers you guys suggested, would it work if the parameter is int or long?
Shouldn't matter.
Doesn't FormatMessage takes only null-terminated strings?
'FormatMessage' is not a standard function. If you're talking about MS
Windows API 'FormatMessage', then just RTFM. It's OT here anyway.
So even if we have a va_list but the arguments in the va_list are long/int, so it still won't work right?
Should, AFAIUI.
Does that mean I still need to convert my long variables to char* right?
What????
How can I do that in a "better" way than just using casting>?
What are you talking about? ks****@gmail.com wrote: Thank you very much for your suggestions. I think that's a good idea. The only thing is that I was wondering if I can create something that is more generic. Because I don't want to just create a single wrapper function for a single call in the program.
The problem is, the parameters' type can be different types (ex, long, int ....etc ). Does anybody know how I can write the wrapper Pete suggested into something that takes in like generic parameters? Is that even possible?
That wrapper function does just what you need. Think about printf --
it's the same sort of thing.
--
Pete Becker
Dinkumware, Ltd. ( http://www.dinkumware.com) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alex |
last post by:
Can anyone point me to any good online references
about the va_arg() va_list() functions/macros
I googled and found a couple of things, but what I found, failed to explain
how it really works...
|
by: shiva |
last post by:
hello,
just i want to write a program which can take unknown number of
integers and sum these numbers using va_list,va_arg...
but, i am not able to recognize the last element in series.can u...
|
by: Jon |
last post by:
Is it possible to modify an argument of a va_list and then pass the
modified va_list to other functions?
void c_fun1(int, va_list args)
{
int *firstIntPointer = &(va_arg(args, int));
...
|
by: skillzero |
last post by:
Is there a portable way to pass a va_list as a parameter to another
function taking a variable argument list?
I have a function that takes a printf-like format string and I'd like
to use...
|
by: ramu |
last post by:
Hi,
Can we intialize va_list to NULL?
ie. va_list = NULL
Regards
|
by: Fred |
last post by:
I've got following program encapsuled fscanf, however, it doesn't
work.
I'm sure that the content format in "a.txt" is OK, the content would
be correctly read if using fscanf directly, what's...
|
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= |
last post by:
On Jun 3, 3:23 am, Jesse Ziser <d...@spam.diewrote:
The relevant paragraph from the Standard is:
---- Begin Quote ----
The type declared is va_list
which is an object type suitable for...
|
by: Laurent Deniau |
last post by:
When I compile the code below with gcc -std=c99 -W -Wall -pedantic -O3
-Winline, it reports the following:
variadic.c: In function ‘fv’:
variadic.c:12: warning: function ‘fv’ can never be...
|
by: raphfrk |
last post by:
Is there any way to pass a variable list to a function, so as to act
as a passthrough?
for example:
void new_printf ( char *buf , ... )
{
va_list vlist;
<modify buf slightly>
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| | |