C++ and (possible) assembly help
Link |
by Children of Lilith
on 2008-05-08 12:32:36 (edited 2008-05-08 12:34:47)
|
I'm still kinda a noob at C++ programming. However, I know that when a program is compiled, when you call a function the program jumps to wherever that function is stored in memory (I think). Does this mean that I can access from within my program the memory address of the beginning of the function? The reason I want to do this is because I'm programming a program that will have the following requirements: The ability to call several different pre-defined functions in a user defined order that will be defined at run-time. The number of possible functions will be very big This variable-function-execution process will be happening a good deal number of times. The following restrictions make me very resistant to the idea of doing the following:
Basically, can I have a variable that stores a function, not a value? Any suggestions? If the above scenario makes no sense, I'll try and clarify what I'm asking for. Thanks in advance |
Re: C++ and (possible) assembly help
Link |
by
on 2008-05-08 12:53:48
|
this sounds like a basic queued-command programming model, and should be very easy to setup. my suggestion is, give it a try and ask a specific question if you get stuck. if you don't know where to begin, start with main. your main function will be a loop, prompting for i commands, and queuing them up. then, once the queue is full, it will execute them in order. |
Re: C++ and (possible) assembly help
|
You can have pointers to functions, but each function pointer must be defined with the same arguments and return type as the function it points to, meaning if you want to execute a bunch of functions you'll probably want them all to take the same args and return type. //Pointer to main int (*ptr_main)(int, char**); ptr_main = &main; |