Question about function call stack
Wed Jan 18 14:56:00 GMT 2006
On Jan 18, 2006, at 1:25 AM, Emmanuel Pacaud wrote:
> Perry Smith a écrit :
>> With C, you can not really assume anything.
>> If you are trying to do this for one particular platform, then
>> you can look at the code generated and eventually figure out how
>> to do what you want to do. If you are doing 32 bit and 64 bit on
>> one platform, then you could #ifdef the two cases.
> That's probably what I'll do. Or find an other way to implement
> what is currently done.
>> But if you truly want portable code, then you need to either use
>> varargs or stdargs. stdargs is part of the C standard I believe.
>> It is pretty easy to use.
> I guess varargs or stdargs are useles here, since the goal is to
> implement a function call with a variable number or arguments, not
> a function with a variable number of arguments.
I'm not sure I understand the difference. Are you trying to call
functions that you can not change? Like call from an interpreter
back into compiled C code?
I've done that before. Maybe I should say I've tried that before.
If you have only integer type arguments, you have a pretty good
chance. But if you have a mix of integers (or longs or shorts) and
floats (or doubles), then it gets very weird and maybe impossible.
This is especially true on some RISC type processors. What I did
finally in my project was I had only a limited number of functions
that I could call and I had glue code from the interpreter back to
the library routine for each of those special cases.
If that is what you are trying to do, you might post this question to
gcc instead of gcc-help.
The problem comes up with RISC architectures because the arguments
never make it to the stack. They are passed in registers. But for
the float and integer case, you have to know what you are passing at
compile time (which the compiler can figure out) -- not at run time.
If you are trying to do that at run time, it seems like you would
almost have to do it in assembly language so you can move argument N
to the general purpose register or the floating point register based
upon its type.
More information about the Gcc-help