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

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 1913
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)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #2
"matevz bradac" <ma*****@email.si> wrote in message
news:cc**************************@posting.google.c om...
[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.google.c om...
[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(numArgs, 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
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...
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 ();
4
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,...
14
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...
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) { ..... }
2
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);...
3
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);...
8
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...
3
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) ...
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: 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
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
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.