开发者

variable names in function definition, call and declaration

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 someth开发者_如何学Going); //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...


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜