473,806 Members | 2,735 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

va_list passthrough

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>

printf( buf , vlist );
}
Jul 7 '08 #1
10 4649
raphfrk wrote:
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>

printf( buf , vlist );
}
Use va_copy.

Jul 7 '08 #2
On Jul 7, 11:03 am, santosh <santosh....@gm ail.comwrote:
raphfrk wrote:
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>
printf( buf , vlist );
}

Use va_copy.

I don't think that is what I want.

I want a program that would allow something like the following to
work.

#include <stdio.h>

int main()
{

int a=7l;

new_printf("%d\ n" , a );

return 0;
}

void new_printf ( char *buf , ... )
{

printf( buf , ... ); // the va list is passed to printf

}

The effect of the above would be that new_printf acts the same as
printf.
Jul 7 '08 #3
On Jul 7, 3:01*pm, raphfrk <raph...@netsca pe.netwrote:
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>

* printf( buf , vlist );

}

Use va_copy.
#include <stdarg.h>
void va_copy(va_list dest, va_list src);

The prototype is self explanatory. How do you plan to modify va_list?
Jul 7 '08 #4
On Jul 7, 11:59 am, rahul <rahulsin...@gm ail.comwrote:
On Jul 7, 3:01 pm, raphfrk <raph...@netsca pe.netwrote:
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>
printf( buf , vlist );
}

Use va_copy.
#include <stdarg.h>
void va_copy(va_list dest, va_list src);

The prototype is self explanatory. How do you plan to modify va_list?

I don't, I want to pass the va_list to the printf function (any
modifications would be to the buf field).
Jul 7 '08 #5
In article <62************ *************** *******@j22g200 0hsf.googlegrou ps.com>,
raphfrk <ra*****@netsca pe.netwrote:
....
>Use va_copy.
#include <stdarg.h>
void va_copy(va_list dest, va_list src);

The prototype is self explanatory. How do you plan to modify va_list?


I don't, I want to pass the va_list to the printf function (any
modification s would be to the buf field).
For some reason, nobody here wants to tell you about the vprintf() function.

This is in line with official, stated, CLC policy - which is to never
give a sucker an even break.

Jul 7 '08 #6
raphfrk <ra*****@netsca pe.netwrites:
On Jul 7, 11:03 am, santosh <santosh....@gm ail.comwrote:
>raphfrk wrote:
Is there any way to pass a variable list to a function, so as to act
as a passthrough?
Only if it accepts a va_list.
for example:
void new_printf ( char *buf , ... )
{
va_list vlist;
<modify buf slightly>
printf( buf , vlist );
}

Use va_copy.


I don't think that is what I want.

I want a program that would allow something like the following to
work.

#include <stdio.h>

int main()
{

int a=7l;

new_printf("%d\ n" , a );

return 0;
}

void new_printf ( char *buf , ... )
{

printf( buf , ... ); // the va list is passed to printf

}

The effect of the above would be that new_printf acts the same as
printf.
Thare are v* versions of the printf family of function for this
purpose. You want vprintf.

--
Ben.
Jul 7 '08 #7
On Jul 7, 12:21 pm, gaze...@xmissio n.xmission.com (Kenny McCormack)
wrote:
In article <623e246f-f0ff-4bbf-a334-a9bb5aecf...@j2 2g2000hsf.googl egroups.com>,ra phfrk <raph...@netsca pe.netwrote:

...
Use va_copy.
#include <stdarg.h>
void va_copy(va_list dest, va_list src);
The prototype is self explanatory. How do you plan to modify va_list?
I don't, I want to pass the va_list to the printf function (any
modifications would be to the buf field).

For some reason, nobody here wants to tell you about the vprintf() function.
Thanks. I guess I can assume from the existance of vprintf, that
there is no way to pass a va_list directly to printf itself ?
This is in line with official, stated, CLC policy - which is to never
give a sucker an even break.
Generally, they will correct every error in your code, including those
unrelated to the original question. However, they usually do also
answer the question too (and the list of errors can be helpful too).
Jul 7 '08 #8
raphfrk wrote:
Thanks. I guess I can assume from the existance of vprintf, that
there is no way to pass a va_list directly to printf itself ?
That's not so bad if you realize if you realize that
printf may use, and frequently does use, vfprintf,
either directly or through vprintf.

int printf(const char *format, ...)
{
int count;
va_list arg;

va_start(arg, format);
count = vprintf(format, arg);
va_end(arg);
return count;
}

int vprintf(const char *format, va_list arg)
{
return vfprintf(stdout , format, arg);
}

I have a toy library.
http://www.mindspring.com/~pfilandr/C/library/std_io.c

--
pete
Jul 7 '08 #9
In article <c7************ *************** *******@m44g200 0hsc.googlegrou ps.com>,
raphfrk <ra*****@netsca pe.netwrote:
>On Jul 7, 12:21 pm, gaze...@xmissio n.xmission.com (Kenny McCormack)
wrote:
>In article
<623e246f-f0ff-4bbf-a334-a9bb5aecf...@j2 2g2000hsf.googl egroups.com>,ra phfrk
<raph...@netsc ape.netwrote:
>>
...
>Use va_copy.
#include <stdarg.h>
void va_copy(va_list dest, va_list src);
>The prototype is self explanatory. How do you plan to modify va_list?
>I don't, I want to pass the va_list to the printf function (any
modification s would be to the buf field).

For some reason, nobody here wants to tell you about the vprintf() function.

Thanks. I guess I can assume from the existance of vprintf, that
there is no way to pass a va_list directly to printf itself ?
Correct. What this means is that every variable-number-of-args function
that exists must have a corresponding v...() version. Luckily, there
aren't very many (off the top of my head, I can only think of the printf
and scanf families) that "come with the system". But it also means that
any that you write yourself, you should also provide a v...() version of.

Which, IMHO, makes the whole va_args functionality rather useless. I
think it mainly exists for backwards compatibility with the existing
printf and scanf families.
>This is in line with official, stated, CLC policy - which is to never
give a sucker an even break.

Generally, they will correct every error in your code, including those
unrelated to the original question.
Human compilers, as they say. And about as useful. If I want a
compiler, I know where to find them.
>However, they usually do also answer the question too (and the list of
errors can be helpful too).
My experience has been otherwise. Note that I am not talking about my
own issues - i.e., I'm not whining about them not answering my questions;
I have long since realized that looking for help here is like looking in
the sewer. I'm talking about my observations of years and years of them
joyously smackin' the newbies given any opportunity.

You may, of course, have another opinion. Fantasies die hard.

Jul 7 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3697
by: Peter | last post by:
-------------------------------------------------------------------------------- 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
3
16782
by: Douwe | last post by:
I try to build my own version of printf which just passes all arguments to the original printf. As long as I keep it with the single argument version everything is fine. But their is also a version which uses the "..." as the last parameter how can I pass them to the orignal printf ? void myprintf(char *txt, ...) printf(txt, ???????); }
2
3348
by: Joerg Schoen | last post by:
Hi folks! I have a function that gets a 'va_list'. I am passing the 'va_list' two times to a function like 'vprintf' to print it out. I thought that this was portable until I came across a platform (AS/400) where it fails: The 'va_list' is actually defined as some some kind of an array, so passing it happens by *reference*: The first user will destroy it and the second
11
3077
by: thierrydollar | last post by:
Hi, I have written a very simple program using variable arguments calls and I get strange things that I cannot explain. I have one function (add) that displays two parameters. It works well when I call it directly. Now I have a second function (set) that also calls add. But this doesn't
7
2865
by: Flash Gordon | last post by:
Reading the standard, va_list is an object type (, so I believe the following should be possible: #include <stdarg.h> void foo(va_list *arg) { /* do some stuff which conditionally might read parameters off arg */ }
1
9477
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 something like %V to pass in another format string and a va_list to allow nesting. It happens to work on my compiler, but I wasn't sure if it's portable to use va_list's as parameters to a variable argument function because va_list isn't always just a...
5
4670
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 holding information needed by the macros
6
4069
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 inlined because it uses variable argument lists variadic.c: In function ‘vf’: variadic.c:12: warning: inlining failed in call to ‘fv’: function not inlinable variadic.c:27: warning: called from here
1
5552
by: Chuck Chopp | last post by:
I have some code that is being built on the following: Windows Server 2003, both 32-bit & 64-bit editions Windows Vista, both 32-bit & 64-bit editions Windows Server 2008, both 32-bit & 64-bit editions Build tools: Visual Studio 2008. SLES 10 SP1, both 32-bit & 64 bit editions
0
9719
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9599
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10111
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3853
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.