Isaac Bavaresco wrote: >> 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? >> To me this seems like a really brain dead choice considering that >> fixed number of ... > > The problem with C is that the compiler relies only on the function > prototypes to check for argument types and number. The prototypes are > usually kept in header files ("*.h"), which are source (text) files. If > the header file is changed one can foil the compiler and say the > function takes any type and number of arguments he wants. But only the compiler. The linker will still only link your call with a function definition that fits the call signature. > Hi-Tech PICC has an interesting approach: It embeds in the object files a > magic number (signature) that says what type and number of arguments it > takes and what type it returns. Then the linker catches such errors. I think this is basically how all C compilers/linkers work. You can compile your source with any old prototype you want, but when you want to link an executable, you need to provide object files that contain the function definitions for exactly the prototypes you used. > Pascal has a good approach with the Units, that include together the code > and the prototypes for everything. A problem with this approach may be that you have to distribute source code for every library you sell. FWIW, a number of C compilers are taking this approach for optimizations: they read whatever is available as source and use the knowledge from this to change how the individual source files are compiled. Gerhard -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist