函数定义、调用和声明中的变量名

发布于 2024-08-27 23:20:34 字数 410 浏览 3 评论 0原文

我看到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

我有两个问题:

  1. 什么约定最好在 C 中使用?;

  2. 无论值是“按值”传递还是通过指针传递,该约定都适用吗?

多谢...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停滞 2024-09-03 23:20:34

函数声明中用于函数参数的名称基本上只是注释。它没有任何意义,并且(正如您所注意到的)不必与函数定义匹配。也就是说,它应该是一个很好的描述性名称,可以告诉您该参数的用途。那么为什么不在声明中使用相同的名称呢?如果您使用不同的名称,并且其中一个名称更好(更具描述性),那么您可能应该在两个地方都使用该名称。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文