I don't know why prototypes are required; I don't pretend to understand the language at all ;>. However, I know what has worked for me. I do not specify parameters myself; defines like ACMD and SPECIAL do it already, however when I'm specifying a function directly, 'gcc' doesn't care if I specify parameters or not; if I do, they have to be in the right order, and if not, there's no problem.. it just assumes what the previous declaration was. Prototyping a function allows the compiler to check that you did not make a mistake when calling any particular function. For example, struct char_data *foo(struct obj_data *object, int mode) By including this prototype (and many functions are prototyped in .h files so they can easily be called anywhere in the program by just including the header file) the compiler will be able to check, at compile time, that every call to the function foo() is done properly. This means not only that the correct number of arguments is passed, and the correct type, but also that the value returned by the function is passed to the correct type of variable. In my example, you must assign the outcome of foo to a pointer to a char_data structure. Disabling prototypes or ignoring errors from them is a bad idea, it entirely defeats the purpose. I think, but I'm not positive, that prototyping can even detect errors in the functions themselves. (I know this kind of error is detected, and I can only assume its a result of prototyping). If a function is declared to return a certain type and the function (through a mistake of the coder) is able to terminate without returning a value, it will generate an error "control returned by a non-void function" or something. Basically, prototypes are one more way of reducing human error without any cost (i think) in the performance of the program. Use them... BTW, ACMD() and SPECIAL() are just macros for prototyping commands and special procedures. Look up their definition (structs.h has SPECIAL, just grep for ACMD) and you'll see that it simply takes your ACMD argument and turns in into a prototype for the function. Very handy. On a side note, I learned this the hard way, that in SPECIAL, one argument is declared as 'void *me'. In a prototype this means that any type could be passed for this argument, and you must cast it into the type you desire.
This archive was generated by hypermail 2b30 : 12/18/00 PST