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

Managing variable argument call

Hello,
I have a function which is coded to receive an unknown number of
arguments
void Process(int i_ss, int Nerr, ...) {
va_list pa; /* variable argument list*/
va_start(pa, Nerr);
sprintf(FMT, "SS=%d, Er=%d ", i_ss, Nerr);
strcat(FMT, "A1=<%s>, A2=<%s> ");
vsprintf(line, FMT, pa);
va_end(pa);
printf("%s\n", line);
fflush(stdout);
}
Here, for simplicity, I treat2 args ,
I want to call this function from a input scenario that will give
textually the type, and value of arguments
I will decode this scenario to call the function
For example a line of scenario could be:
S=P1 S=P2
The I will cal with 2 strings
S=P1 S=P2 I=13
The I will cal with 2 strings and one int
Obviouly I need to have a format which is suitable for that.
--
I have made some experience with "alloca"
for allocation space in the stack, "pushing" arguments on the stack
and calling the function.
snippet: ARGS has been set previously
-------------------------------------------------------------------------------------
parguments = (void*) alloca(size); /* 8 in the case depicted
(2 char pointers) */
for (p=0; p < nargs;p++){
/* Get the code for the argument
*/
switch(ARGS[p].code){
case 'S' :
*(((char**)parguments)++) = ARGS[p].str; //P1
break;
case 'I' :
/* value
*/
*(((int*)parguments)++) = ARGS[p].vali; //P2
break;
default:
;
}
}
Process(i_ss, NumError);
-------------------------------------------------------------------------------------
But no succes until now!!
I am working under Windows or Linux with gcc 3.2.X (same bad results)
Has anyone an idea how to code this?
Thanks

Apr 5 '06 #1
1 1529
In article <11**********************@j33g2000cwa.googlegroups .com>
<sp*********@wanadoo.fr> wrote:
I have a function which is coded to receive an unknown number of
arguments
(You mean "variable number of arguments", in Standard-ese anyway.)
... I want to call this function from [some other function

that needs to supply the variable number of arguments By Magic.]

This is in the FAQ. See the comp.lang.c FAQ, question 15.13
(<http://c-faq.com/varargs/invvarargs.html>).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (40°39.22'N, 111°50.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Apr 5 '06 #2

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

Similar topics

83
by: Alexander Zatvornitskiy | last post by:
Hello All! I'am novice in python, and I find one very bad thing (from my point of view) in language. There is no keyword or syntax to declare variable, like 'var' in Pascal, or special syntax in...
2
by: Suzanne Vogel | last post by:
'stdarg.h' defines the 'va_arg' type to use in passing variable numbers of parameters to functions. The example of its use given in the Dinkumware documentation *seems* to imply that the 'va_arg'...
7
by: | last post by:
How to call a function with variable argument list from another function again with variable argument list? Example : double average ( int num, ... ); double AFunct1 ( int num, ... ); double...
134
by: James A. Donald | last post by:
I am contemplating getting into Python, which is used by engineers I admire - google and Bram Cohen, but was horrified to read "no variable or argument declarations are necessary." Surely that...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
5
by: matevz bradac | last post by:
Hi, I'm trying to implement delayed function execution, similar to OpenGL's display lists. It looks something like this: beginList (); fcn1 (); fcn2 ();
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
6
by: CptDondo | last post by:
How do you declare a function with 0 or mroe arguments? I have a bunch of functions like this: void tc_cm(int row, int col); void tc_do(void); void tc_DO(int ln); and I am trying to ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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
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.