函数定义、调用和声明中的变量名
我看到C书籍在函数定义、调用函数和声明中使用相同的变量名。其他人在调用函数和声明/原型中使用相同的变量名,但在定义中使用不同的变量名,如下所示:
void blabla(int something); //prototype
blabla(something) // calling function inside main after something has been initialized to int
void blabla(int something_else) //definition
我有两个问题:
什么约定最好在 C 中使用?;
- ?无论值是“按值”传递还是通过指针传递,该约定都适用吗?
多谢...
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:
What convention is best to use in C?;
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
函数声明中用于函数参数的名称基本上只是注释。它没有任何意义,并且(正如您所注意到的)不必与函数定义匹配。也就是说,它应该是一个很好的描述性名称,可以告诉您该参数的用途。那么为什么不在声明中使用相同的名称呢?如果您使用不同的名称,并且其中一个名称更好(更具描述性),那么您可能应该在两个地方都使用该名称。
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.