views:

53

answers:

1

Hi, I see C books that use the same variable names in the function definition, calling function and declaration. Others use the same variable names in the calling function and in the declaration/prototype but a different one in the definition as in:

void blabla(int something); //prototype

blabla(something)  // calling function inside main after something has been initialized to int 

void blabla(int something_else)  //definition

I have two questions:

  1. What convention is best to use in C?;

  2. Does the convention apply regardless whether a value is being passed "by-value" or if it's being passed by a pointer?

Thanks a lot...

+1  A: 

The name used for a function parameter in a function declaration is basically just a comment. It doesn't have any meaning and (as you've noticed) doesn't have to match the function definition. That said, it should be a good descriptive name that tells you what the parameter is for. So why not use the same name in the declaration? If you use a different name and one of the names is better (more descriptive), then you should probably use that name in both places.

Chris Dodd
Thanks. So basically it's good to use a single descriptive name which will go equally well in the declaration, calling function and definition. No need to invent other different variable names?
yCalleecharan
Given two names, either one of them is clearly better than the other - in which case you would do well by using the better one in both places - or both are equally meaningless ;) - in which case you should choose one and stick to it if only for the sake of consistency.
Pavel Minaev
So it's best to have the same name in the declaration and in the definition. And then we can put another names in the calling function.
yCalleecharan