473,569 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

storing variable arguments for future use

Hi,

I'm trying to implement delayed function execution,
similar to OpenGL's display lists. It looks something
like this:

beginList ();
fcn1 ();
fcn2 ();
Nov 14 '05 #1
4 1937
matevz bradac <ma*****@email. si> spoke thus:
When execList() is called, fcnToCall (numArgs, ...) should
be executed. The problem is, how do I store variable args
for future use? I know they're all long ints, so this should
be somehow helpful, but I can't figure it out. Do I have to
remember/copy the stack and is this possible in C, or must it
be done in assembly?


Have you looked at the functions in <stdarg.h>? They sound like
they'd help you a lot.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cybers pace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #2
"matevz bradac" <ma*****@email. si> wrote in message
news:cc******** *************** ***@posting.goo gle.com...
[snip]
When execList() is called, fcnToCall (numArgs, ...) should
be executed. The problem is, how do I store variable args
for future use? I know they're all long ints, so this should
be somehow helpful, but I can't figure it out. Do I have to
remember/copy the stack and is this possible in C, or must it
be done in assembly?


Assembly is probably the only way to do exactly what you describe,
unfortunately. Using the functions in <stdarg.h>, you could store a
suitably-sized array of the longs (when creating the function list), but
that wouldn't help much as there's no way in standard C to construct the
call to the variadic function.
Nov 14 '05 #3

In article <c5************ @ID-149533.news.uni-berlin.de>, "Alex" <me@privacy.net > writes:
"matevz bradac" <ma*****@email. si> wrote in message
news:cc******** *************** ***@posting.goo gle.com...
[snip]
When execList() is called, fcnToCall (numArgs, ...) should
be executed. The problem is, how do I store variable args
for future use?


Assembly is probably the only way to do exactly what you describe,
unfortunately. Using the functions in <stdarg.h>, you could store a
suitably-sized array of the longs (when creating the function list), but
that wouldn't help much as there's no way in standard C to construct the
call to the variadic function.


I couldn't tell from the OP's description, but this might be another
case where the problem can be solved by implementing the real function
as a non-variadic one with a variadic wrapper. That is:

int fcnToCallV(long numArgs, va_list Args);

int fcnToCall(long numArgs, ...)
{
va_list Args;
int Ret;

va_start(Args, numArgs);
Ret = fcnToCallV(numA rgs, Args);
va_end(Args);

return Ret;
}

(The OP didn't mention a return type for these functions, so I assumed
int.)

Then the OP's call-list system stores a call to fcnToCall as one to
fcnToCallV, by doing the va_start before storing it and the va_end
when processing the list, after the call returns.

--
Michael Wojcik mi************@ microfocus.com

The movie culminated with a bit of everything. -- Jeremy Stephens
Nov 14 '05 #4
This is exactly what I want. I was hoping there's an easy
way of, well, memcpy()-ing the stack, and then passing it
to some function... -> assembly it will have to be.

Thanks,
matevz

"Alex" <me@privacy.net > wrote in message news:<c5******* *****@ID-149533.news.uni-berlin.de>...
Assembly is probably the only way to do exactly what you describe,
unfortunately. Using the functions in <stdarg.h>, you could store a
suitably-sized array of the longs (when creating the function list), but
that wouldn't help much as there's no way in standard C to construct the
call to the variadic function.

Nov 14 '05 #5

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

Similar topics

2
1760
by: Francisco | last post by:
I have this problem: I have a database with information about games, and users are able to vote for them. Everytime a user votes for a game I store the unique game name into a session variable (an array). So if they are in a page were they already voted, they won't have the option to do so. The idea is that the session cookie lasts "forever",...
5
411
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 ();
4
13560
by: Augustus S.F.X Van Dusen | last post by:
I have recently come across the following construction: #define P_VAR(output, string, args...) \ fprintf (output, "This is "string"\n", ##args) which can be invoked as follows: int x = 1, y = 2 ; char * str = "String" ;
14
5818
by: Luiz Antonio Gomes Pican?o | last post by:
How i can store a variable length data in file ? I want to do it using pure C, without existing databases. I'm thinking to use pages to store data. Anyone has idea for the file format ? I want to store data like a database: ---------------------------------- Custumer:
23
19150
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) { ..... }
2
2479
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j); void funcY(int i, int j,char *name);
3
2504
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j); void funcY(int i, int j,char *name);
8
1991
by: Fredrik Tolf | last post by:
I've been trying to get the string formatting operator (%) to work with more arguments than the format string requires, but I can find no way to do that. For example: '10' Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: not all arguments converted during string formatting The thing is, I want to get format...
3
2252
by: Seth Gecko | last post by:
Hi I am working with generic lists of various objects and a control dealing with these lists. For instance: A parent form holds: dim Walls as List(Of wall) dim Segments as List(Of segment) The parent form have a custom control, which have a public sub looking
0
7698
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...
0
7924
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, 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. ...
0
7970
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...
1
5513
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2113
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
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
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...

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.