473,396 Members | 2,029 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,396 software developers and data experts.

Constructing/modifying va_lists

Hi,

I have a question about using va_lists. I have a pair of text
formatting functions defined as follows:

void fmt1(char *format,va_list l) {
// ...
}

void fmt2(char *format,...) {
va_list l;
va_start(l,format);
// ...
fmt1(format,?);
// ...
va_end(l);
}

I'd like fmt2() to examine the va_list, replace some of the arguments
(based on the format string), then call fmt1() with either the modified
va_list or a newly constructed one. Is this possible? I'm sure I've
seen this being done somwhere...

Thanks in advance,
Ross

Aug 22 '06 #1
4 1462
Ross wrote:
Hi,

I have a question about using va_lists. I have a pair of text
formatting functions defined as follows:

void fmt1(char *format,va_list l) {
// ...
}

void fmt2(char *format,...) {
va_list l;
va_start(l,format);
// ...
fmt1(format,?);
// ...
va_end(l);
}

I'd like fmt2() to examine the va_list, replace some of the arguments
(based on the format string), then call fmt1() with either the modified
va_list or a newly constructed one. Is this possible? I'm sure I've
seen this being done somwhere...
The machinery of C can't do it: The only means C has for
building an argument list is to write a list of arguments in
a function call.

If you've seen it done somewhere, the doing involved either
some kind of extensions to the C language or some extra-linguistic
knowledge about how a particular implementation handles function
arguments, possibly both.

--
Eric Sosman
es*****@acm-dot-org.invalid

Aug 22 '06 #2
Just to add here , when you say va_list, you are refering to pointer
which runs on stack of fuction. To understand that, we need to know how
variables arguments are implemented.

Thanks
Shaan
Eric Sosman wrote:
Ross wrote:
Hi,

I have a question about using va_lists. I have a pair of text
formatting functions defined as follows:

void fmt1(char *format,va_list l) {
// ...
}

void fmt2(char *format,...) {
va_list l;
va_start(l,format);
// ...
fmt1(format,?);
// ...
va_end(l);
}

I'd like fmt2() to examine the va_list, replace some of the arguments
(based on the format string), then call fmt1() with either the modified
va_list or a newly constructed one. Is this possible? I'm sure I've
seen this being done somwhere...

The machinery of C can't do it: The only means C has for
building an argument list is to write a list of arguments in
a function call.

If you've seen it done somewhere, the doing involved either
some kind of extensions to the C language or some extra-linguistic
knowledge about how a particular implementation handles function
arguments, possibly both.

--
Eric Sosman
es*****@acm-dot-org.invalid
Aug 22 '06 #3
Ross wrote:
Hi,

I have a question about using va_lists. I have a pair of text
formatting functions defined as follows:

void fmt1(char *format,va_list l) {
// ...
}

void fmt2(char *format,...) {
va_list l;
va_start(l,format);
// ...
fmt1(format,?);
// ...
va_end(l);
}

I'd like fmt2() to examine the va_list, replace some of the arguments
(based on the format string), then call fmt1() with either the modified
va_list or a newly constructed one. Is this possible? I'm sure I've
seen this being done somwhere...

Thanks in advance,
I have to ask, what is wrong with:
void fmt1 (char *format, ...)
{
...
}

void fmt2 (char *format, ...)
{
va_list all_args;
va_start (all_args, format);
/* Extract and modify all the args and
* store them in variables T1, T2, T3 ... Tn.
*/
if (case1) {
fmt1 (format, T1, T2, T3); /* up to Tn */
} else if (case2) {
fmt1 (format, T2, T3, T1);
} else if (case3) {
fmt1 (format, T3, T1, T2);
} /* carry on in this form for all the cases you need */
va_end (all_args);
}

Admittedly, fmt2 turns out a little verbose and
cannot easily handle all different cases that may
result.

The /other/ way is to design your own parameter
passing method and use that instead (storing
values in filescope variables, carrying type information,
etc).

goose,

Aug 22 '06 #4
"shaanxxx" <sh******@yahoo.comwrites:
Just to add here , when you say va_list, you are refering to pointer
which runs on stack of fuction. To understand that, we need to know how
variables arguments are implemented.
Please don't top-post. Read <http://www.caliburn.nl/topposting.html>.

When you say va_list, you are referring to a va_list, which behaves as
the standard specifies. It is simply "an object type suitable for
holding information needed by the macros va_start, va_arg, va_end, and
va_copy". The standard doesn't even use the word "stack".

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 22 '06 #5

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

Similar topics

16
by: Japcuh | last post by:
How do you write self modifying code in Java? Japcuh (Just Another Perl C Unix Hacker) http://www.catb.org/~esr/faq/hacker-howto.htm#what_is ..0. ...0 000
6
by: qwweeeit | last post by:
Hi all, when I was young I programmed in an interpreted language that allowed to modify itself. Also Python can (writing and running a module, in-line): fNew =open("newModule.py",'w') lNew=...
0
by: Krasimir_Slaveykov | last post by:
Hello , I have a problem with constructing correct SQL. I have tables: TABLE1 wich have FIELD1 and FIELD2 TABLE2 wich have FIELD1 and FIELD2 TABLE3 wich have FIELD1, FIELD2 and FIELD3 I...
3
by: karthick | last post by:
Hi, I am constructing a Message (Body) for sending our Emails. It is around 3000 characters long. But for whatever reason, the last line seems to be broken with a "!" exclamatory mark in it,...
1
by: cainlevy | last post by:
Hey all, What are the pros and cons of defining methods in the constructor vs through the prototype? For example: Constructing: ------------- function MyObj() { this.MyMethod = function()...
19
by: Michael Schuerig | last post by:
In my experience most available books and web publication on CSS are related to web page/site design. Little attention is payed to the design and construction of web-based application for data...
13
by: Robin Becker | last post by:
When young I was warned repeatedly by more knowledgeable folk that self modifying code was dangerous. Is the following idiom dangerous or unpythonic? def func(a): global func, data data =...
26
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
5
by: IUnknown | last post by:
Ok, we are all aware of the situation where modifying the folder structure (adding files, folders, deleting files, etc) will result in ASP.NET triggering a recompilation/restart of the application....
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
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...
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
jinu1996
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...
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
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,...
0
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...

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.