473,395 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Nested variadic functions

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

Nov 12 '07 #1
4 4902
In article <11*********************@57g2000hsv.googlegroups.c om>,
Boltar <bo********@yahoo.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
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Nov 12 '07 #2
On Mon, 12 Nov 2007 02:37:46 -0800, Boltar <bo********@yahoo.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
Nov 12 '07 #3
On Nov 12, 3:37 pm, Boltar <boltar2...@yahoo.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

Nov 12 '07 #4
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

Nov 13 '07 #5

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

Similar topics

2
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...
3
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...
5
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...
19
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...
2
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...
2
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......
2
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...
2
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, ...) {
4
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);
0
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
Oralloy
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,...
0
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...
0
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...

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.