Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between including a parameter name in a function declaration and not including one?

I remember reading before about the significance (or lack thereof) between including a parameter name in a function declaration and not including one. But I can't remember what it was that I read or where I read it.

for example,

void do_something(int *); // No parameter name included, only type.

vs...

void do_something(int * i); // type AND parameter name included.

So what's the difference between these two declarations? Thanks for reading and maybe answering this possibly trivial question.

-- UPDATE --

Okay, so the thing I had read was a set of style guidelines from an old professor of mine warning against including a parameter name in function definition and NOT using the parameter in the function.

void do_something(int * i) { //code that doesn't use i;} //BAD
void do_something(int *) { //code that doesn't use i;} //OK
like image 807
zebraman Avatar asked Nov 10 '10 23:11

zebraman


3 Answers

There is no difference, as far as the compiler is concerned.

Adding meaningful parameter names is a helpful form of documentation, though.

like image 74
Oliver Charlesworth Avatar answered Nov 03 '22 01:11

Oliver Charlesworth


The difference is that the second version could be more readable if you choose a good parameter name. Nothing more to say ;-)

like image 28
frast Avatar answered Nov 02 '22 23:11

frast


There is no technical difference between those declarations. If you instead had

void accumulate_stats(int * count);

or something similarly descriptive, it would be an improvement in self-documentation.

like image 39
aschepler Avatar answered Nov 02 '22 23:11

aschepler