Is there anyway to determine the number of arguments on the stack? Ie a way to find the number of hidden arguments passed to a function.
Is there anyway to determine the number of arguments on the stack? Ie a way to find the number of hidden arguments passed to a function.
Hidden arguments? Are you asking about variable argument lists?
In general, there is no single answer to your question, as different compilers/CPU architectures have different subroutine linkage conventions and mechanisms. Linkage pointers, parameter counts, and simply blind faith have all been used.
If you're talking about printf() like functions, varargs is the standard way to deal with them.
Insert obnoxious but pithy remark here
I mean something like this
The question arises from a comment made by one of the NetBSD engineers. He had made a comment that if there was one hidden argument, then there would be N args, but N+1 arguments on the stack for non-static functions. I just wanted to see how much truth there was to this statement.Code:#include <stdio.h> int prabs(int i){ int v = i < 0 ? -i : i; printf("%d\n",v); return v; } int main(void){ prabs(5); return 0; }
Or it could be I just missed the larger context in which he was speaking of at the time.
Probably talking about the 'this' pointer which is usually passed as a hidden parameter when using member functions of a C++ class.
As for C, that's highly implementation specific.