On Thu, 23 Oct 2008, Olin Lathrop wrote: > Isaac Marino Bavaresco wrote: > > With the callee cleaning the stack it would be impossible (or at least > > very difficult) to have functions with variable-length argument lists > > like printf. > > > > For some architectures it adds more complexity also, because first the > > return address need to be removed from the stack and saved, then the > > stack pointer must be incremented (decremented for some) and the return > > address finally used to return. > > On the PIC 18 there are separate data and return address stacks, so this is > not a issue. I didn't realize that all C functions are allowed to be called > with different number of arguments. Is this really the case? Yes and no. Originally a function call just pushed things onto the stack and the function itself expected the right things to be there when it was called. The compiler did very little checking for you. varible argument lists were accessed using a simple pointer to the memory after the last known argument. This caused problems with register based argument passing optimisations (e.g. SPARC). C compilers grow up a little with the introduction of function prototypes (the compiler actually checking the formal parameter list against the actual parameter list) and type safe linking. > To me this > seems like a really brain dead choice considering that fixed number of > arguments is common and knowing that at compile time allows for some obvious > optimizations. I can see the point to variable numbers of arguments, but I > also don't see a drawback to making you say this is a possibility in the > routine declaration. I think the variable number of arguments thing was originally really a side effect rather than a goal. Yes nowadays you need to explicitly say that unknown arguments may follow the defined ones using "..." at the end of the formal arg list. > The compiler can then catch accidental wrong number of > arguments supplied in the majority of cases where you intend to always call > with the fixed list of arguments. Is C really defined to not allow for > this? no. Regards Sergio Masci -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist