When declaring functions in C, you should set a prototype in which you do not need to write the name of parameters. Just with its type is enough.
void foo(int, char);
My question is, is it a good practice to also include names of parameters?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, it’s considered good practice to name the arguments even in the prototypes.
You will usually have all your prototypes in the header file, and the header may be the only thing your users ever get to inspect. So having meaningful argument names is the first level of documentation for your API.
Likewise, comments about the what the functions do (not how they’re implemented, of course) should go in the header, together with their prototypes.
A well-written header file may be the most important part of your library!
As a curious aside, constness of arguments is an implementation detail. So if you don’t mutate an argument variable in your implementation, only put the
constin the implementation: