: Yuan Zhong wrote:
:> Hi, Can someone please explain me what's going on during a call to a
:> function. Specifically, I wanted to know what's going on in Stacks.
:>
: In some compilers, the parameters are "pushed" onto a stack. Other
: implementations pass parameters via registers.
: Upon a return, some implementations place the return value on the
: stack. The popping of arguments off of the stack may be the
: responsibility of the calling protocol or the function's protocol.
: Some implementations can pass return values via registers.
:> Why is it ok to pass only 2 parameters or 5 parameters when the function
:> prototype requires 3.
:>
:> thanks.
:>
: Show the code.
This is code I tested under gcc3.3.2
It compiles successfully whether I pass one parameter or more than two.
Any explainations? Thanks.
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
char* cmp_string(char *a, char *b)
{
return (strlen(a)>strlen(b)?a:b);
}
int main(void)
{
char *a="hello", *b="hello, world\n";
char *(*f)();
f=&cmp_string;
printf("the longer one is %s", f(a,b,"hello","blah blah"));
printf("the longer one is %s", f(a));
return 0;
}
: In C++, parameters can be assigned default values. So that if the
: parameter is not supplied by the caller, the function receives
: the default value. But, that is an issue for another newsgroup.
: --
: Thomas Matthews
: C++ newsgroup welcome message:
:
http://www.slack.net/~shiva/welcome.txt
: C++ Faq:
http://www.parashift.com/c++-faq-lite
: C Faq:
http://www.eskimo.com/~scs/c-faq/top.html
: alt.comp.lang.learn.c-c++ faq:
:
http://www.raos.demon.uk/acllc-c++/faq.html
: Other sites:
:
http://www.josuttis.com -- C++ STL Library book