Hi
I think I posted a question similar to this on here a while back but I
can't find the thread and I need something more general anyway.
My problem is I have 2 variadic functions , one of which needs to call
the other passing its entire argument list but the other needs to be
callable from anywhere else in the program as a variadic too, ie it
*can't* have va_list as a paramater type.
eg:
void func1(char *fmt, ...)
{
prepend something to format
func2(fmt,args) ;
}
void func2(char *fmt,...)
{
}
Is this possible? Nothing I try seems to work.
Thanks for any help
B2003 4 4934
In article <11************ *********@57g20 00hsv.googlegro ups.com>,
Boltar <bo********@yah oo.co.ukwrote:
>My problem is I have 2 variadic functions , one of which needs to call the other passing its entire argument list but the other needs to be callable from anywhere else in the program as a variadic too, ie it *can't* have va_list as a paramater type.
Have two versions of each function: one with a va_list argument and
a variadic one which just calls the other one. Then calls between
them can just use the va_list version.
The *printf() functions follow this pattern - fprintf(), vfprintf(),
fscanf(), vfscanf() etc.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
On Mon, 12 Nov 2007 02:37:46 -0800, Boltar <bo********@yah oo.co.uk>
wrote:
>My problem is I have 2 variadic functions , one of which needs to call the other passing its entire argument list but the other needs to be callable from anywhere else in the program as a variadic too, ie it *can't* have va_list as a paramater type.
eg:
void func1(char *fmt, ...) {
prepend something to format
func2(fmt,args) ; } void func2(char *fmt,...) {
}
How about if you provide variadic interfaces for your func1() and
func2(), and wrap the stuff that was in func2() into a new func3()
which can accept a va_list.
#include <stdio.h>
#include <stdarg.h>
void func1(char *fmt, ...)
{
/* prepend something to fmt, giving newfmt */
va_list args;
va_start (args, fmt);
func3 (newfmt, args);
va_end (args);
}
void func2(char *fmt, ...)
{
/* leave fmt unchanged */
va_list args;
va_start (args, fmt);
func3 (fmt, args);
va_end (args);
}
void func3(char *fmt, va_list arglist)
{
/* do stuff with fmt and arglist - probably like this: */
vfprintf(stderr , fmt, arglist);
}
I'm doing something similar to this - albeit in C++ - with a debug
logging class, where my equivalent of func3 is private, and I provide
a number of public interfaces which are variadic.
--
PGP key ID 0xEB7180EC
On Nov 12, 3:37 pm, Boltar <boltar2...@yah oo.co.ukwrote:
Hi
I think I posted a question similar to this on here a while back but I
can't find the thread and I need something more general anyway.
My problem is I have 2 variadic functions , one of which needs to call
the other passing its entire argument list but the other needs to be
callable from anywhere else in the program as a variadic too, ie it
*can't* have va_list as a paramater type.
eg:
void func1(char *fmt, ...)
{
prepend something to format
func2(fmt,args) ;
}
void func2(char *fmt,...)
{
}
Is this possible? Nothing I try seems to work.
Hi,
Apart from refactoring your code to work with variadics, you can
look for compiler extensions which might help. GNU c compiler for
example, has __builtin_apply _args()
Just a thought...
Best regards,
Pranav
--------------------------------------------------------------------------
Software gets slower faster than hardware gets faster. - Niklaus Wirth
Boltar wrote:
I think I posted a question similar to this on here a while back but I
can't find the thread and I need something more general anyway.
My problem is I have 2 variadic functions , one of which needs to call
the other passing its entire argument list but the other needs to be
callable from anywhere else in the program as a variadic too, ie it
*can't* have va_list as a paramater type.
Introduce a third function with a va_list arg that both variadic functions
call.
--
Chris "sharing is all" Dollin
Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Loony |
last post by:
Hi,
I want to use variadic functions with stl containers as arguments but
I am not sure if that is possible and if so how.
I'm using gcc 3.3 on Suse 8.2
Hope someone can help me.
Thanx in advance
|
by: Loony |
last post by:
Hi,
I have a problem with my code. I am using a virtual class in which I
define a variadic function. This class is inherited by another one
which then implements it. The problem occurs while linking:
undefined reference to `vtable
undefined reference to `typeinfo
I'm using gcc 3.3 to compile the code.
|
by: Christopher Benson-Manica |
last post by:
Do variadic functions (such as printf()) always scan the format string
for format specifiers, even when there are no additional arguments?
If it is instead a QoI issue, what would be true for a typical
implementation?
Basically, I'm wondering whether there is any advantage to using
puts() instead of printf() for output of a string.
--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
|
by: Ross A. Finlayson |
last post by:
Hi,
I hope you can help me understand the varargs facility.
Say I am programming in ISO C including stdarg.h and I declare a
function as so:
void log_printf(const char* logfilename, const char* formatter, ...);
Then, I want to call it as so:
|
by: Florian G. Pflug |
last post by:
Hi
I faintly remember that I once stumbled upon a way to declare variadic
functions (functions that take a variable number of arguments) in plpgsql -
but I just searched the docs and can't find any reference to variadic
functions.
So - please enlighten me - are there variadic functions in plpgsql, or are
there none?
| |
by: pinkfloydhomer |
last post by:
Can I use printf inside a variadic function that I am writing?
Like:
void print(const char * format,...)
{
va_list va;
va_start(va, format);
char buffer; // yeah, I know...
vsprintf(buffer, format, va);
|
by: baranikumarhtsl |
last post by:
Hi all,
Its again me only.... no only i am learning variadic functions topic and as soon as i completed i thought to write a example function . but i got stuck up!....
See i wants to write a variadic function called xstrcpy() in which the minimum number of arguments should be 2 and max is virtually the maximum number the c compiler supports. but i don't want a parameter to specify how many arguments that i am going to pass at the...
|
by: Boltar |
last post by:
Hi
Is it possible to next variadic functions. Eg if I wish to do
something like this...
void mainfunc(char *fmt, ...)
{
|
by: Boltar |
last post by:
Hi
Is it possible to nest variadic functions? Eg to do something like
this:
void mainfunc(char *fmt, ...)
{
va_list args;
va_start(args,fmt);
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
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...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |