把在C函数原型参数的名字吗? [英] Put name of parameters in C function prototypes?

查看:101
本文介绍了把在C函数原型参数的名字吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用C声明函数,你应该设置一个原型中,你不需要写参数的名称。只是它的类型是不够的。

When declaring functions in C, you should set a prototype in which you do not need to write the name of parameters. Just with its type is enough.

     void foo(int, char);

我的问题是,它是一个很好的做法,还包括参数的名字呢?

My question is, is it a good practice to also include names of parameters?

推荐答案

是的,它被认为很好的做法来命名的参数甚至在原型。

Yes, it's considered good practice to name the arguments even in the prototypes.

您通常在头文件中的所有的原型,头可能是用户曾经去视察的唯一的事情。因此,有有意义的参数名称是文件的第一级为您的API。

You will usually have all your prototypes in the header file, and the header may be the only thing your users ever get to inspect. So having meaningful argument names is the first level of documentation for your API.

同样,有关评论什么功能做(他们不是如何实现的,当然)应与其原型去头,在一起。

Likewise, comments about the what the functions do (not how they're implemented, of course) should go in the header, together with their prototypes.

一个写得很好的头文件可能是你的库中最重要的部分!

A well-written header file may be the most important part of your library!

<子>作为一个好奇的一边,参数常量性是一个实现细节。所以,如果你没有在执行变异参数变量的只有的把常量在执行

/* Header file */

/* Computes a thingamajig with given base
 * in the given number of steps.
 * Returns half the thingamajig, or -1 on error.
 */
int super_compute(int base, int steps); 

/* implementation file */

#include "theheader.h"

int super_compute(const int base, int steps)
{
  int b = 2 * base;
  while (--steps) { b /= 8; } /* no need for a local variable :-) */
  return -1;
}

这篇关于把在C函数原型参数的名字吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆