by bigfoot · 12y ago · 0 comments
"In function prototypes, include parameter names with their data types. Although this is not required by the C language, it is preferred in Linux because it is a simple way to add valuable information for the reader."
OpenBSD enforces this:
"Prototypes should not have variable names associated with the types; i.e., void function(int); not: void function(int a);"
Instead of letting the code tell the parameters' purposes, this now has to be deduced from informal descriptions, or the function definition in some .c file.
//decl in the header
int pow(int exponent, int base);
if you only look at the header you might think that the arguments are one way, but //actual definition
int pow(int base, int exponent){
//math is correct but base <-> exponent..
}
i'm not saying i agree with this at all - it's a contrived example..!The bug in that CVE is that the function call got the parameter order wrong. The declaration was correct AFAICT, and of course completely irrelevant because you can make that mistake regardless of what the header says.
Parameters in headers are just documentation, by definition. Documentation can be wrong however you write it, but in general it helps to have it instead of not. Would you seriously argue that function parameters should not be given names in documentation?
That way, you could repeat yourself safely, since the repetition would be checked by the compiler.