zebraman
zebraman

Reputation: 2522

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

Upvotes: 7

Views: 1497

Answers (5)

cHao
cHao

Reputation: 86585

For a forward declaration, it doesn't make any difference.

In the actual definition, a parameter without a name isn't checked for use. It's a way to have unused parameters without some UNUSED_PARAM(x) macro or some other trickery whose only purpose is to shut the compiler up about it.

Upvotes: 0

aschepler
aschepler

Reputation: 72483

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.

Upvotes: 1

Merlyn Morgan-Graham
Merlyn Morgan-Graham

Reputation: 59151

In a forward declaration, there should be no difference. They will both describe the same memory layout for the call, so they should be completely interchangeable.

Upvotes: 0

frast
frast

Reputation: 2740

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

Upvotes: 1

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272812

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

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

Upvotes: 12

Related Questions