ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is it ok to omit the parameter's names on functions prototypes? I know it will give you more information about what the function expects exactly, but I always put a comment box on top of my functions explaining what my parameters are gonna be used for.
Distribution: Ubuntu, Debian, Various using VMWare
Posts: 2,088
Rep:
You can omit the parameter's name on a function prototype, however I would say best practice would be to include it.
You should code in a style that makes it easy for others to see what is going on, easy for you to see what you have written and to prevent mistakes.
One thing about commenting - what if you update the function prototype but forget to update the comment? You will then have unclear code with a contradictory comment. Including the parameter name prevents this.
One thing about commenting - what if you update the function prototype but forget to update the comment? You will then have unclear code with a contradictory comment. Including the parameter name prevents this.
And what if you update the function definition in a way that changes the name and meaning (but not the type) of one of the parameters, but forget to update the prototype? You will then have unclear code with a prototype which is contradictory for humans, though not for the compiler.
Unlikely, but realize that the parameter name in a prototype is just another comment.
I actually have to deal with legacy code where the programmer felt, for whatever reason, he didn't need names on his prototypes (and sometimes even his implementation classes: no kidding!)
There are situations where it can be useful not to include the parameter names. (Whether "useful" is the right word I'm not sure) I have some functions that are used just as callback functions but they do not always require the parameter that will be passed in, for those functions I omit the parameter name in the function definition, thus avoiding warning from the compiler but I still tend to keep them in the declaration, for clarity, but omitting it would indicate (to me) that they were not needed by the function.
they do not always require the parameter that will be passed in, for those functions I omit the parameter name in the function definition, thus avoiding warning from the compiler
Just for the record:
they're errors, not warnings; and
one avoids these errors not by omitting parameter names, but including them.
To see this in action, run the following bash script:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.