[英]What does getint (int *) mean?
getint (int *);
I am not really sure what does getint (int *)
mean? 我不太确定getint (int *)
是什么意思? Can someone explain this? 有人可以解释吗?
This is a function prototype declaring the function getint()
. 这是一个声明函数getint()
的函数原型。 The function takes as pointer to an int
as a parameter. 该函数将指向int
指针作为参数。
When prototyping a function it is not necessary to specify the parameters' names. 在对函数进行原型设计时,无需指定参数名称。
The prototype is missing a return type, which for C then defaults to int
. 原型缺少返回类型,对于C,该返回类型默认为int
。 Omiting a return type however is violating the recent C standard, so code doing so could be considered invalid. 但是,省略返回类型会违反最新的C标准,因此这样做的代码可能被视为无效。
An equivalent to 相当于
getint(int *);
though would be 虽然会
int getint(int * pi);
TL;DR getint (int *);
TL; DR getint (int *);
is a forward declaration for a function, in a very bad programming style. 是一种非常糟糕的编程风格的函数前向声明。 Without any explicit return type, it will default to int
. 没有任何显式的返回类型,它将默认为int
。
The recommended way to write is is to specify the return type explicitly, like 推荐的写方法是显式指定返回类型,例如
if int
, like 如果是int
,例如
int getint(int *); //yes, omitting the identifier name is correct, see note below
or, 要么,
int getint(int * outVar); //we can have the name, if we want.
if void
, like 如果void
,像
void getint(int *);
or, 要么,
void getint(int * outVar);
or any return type you want. 或您想要的任何返回类型。
NOTE: 注意:
Just for further reference, from C11
, chapter §6.7.6.3, Function declarators , (emphasis mine) 仅供参考,从C11
第6.7.6.3节“ 函数声明符”(强调我的)开始
If, in the declaration
'T D1'
,D1
has the form 如果在声明'T D1'
中D1
具有以下形式:D( parameter-type-list )
... ...
A parameter type list specifies the types of, and may declare identifiers for, the parameters of the function. 参数类型列表指定函数参数的类型,并可以声明该函数的参数的标识符 。
So, the identifier name is optional. 因此,标识符名称是可选的。
The code is not valid C. If it compiles, consider upgrading to a compiler which is not older than 15 years. 该代码无效C。如果可以编译,请考虑升级到不超过15年的编译器。
History lesson: 历史课:
In older, obsolete versions of the C standard you were allowed to omit the return type when writing a function declaration, in which case getint(int *);
在较旧的C标准版本中,允许您在编写函数声明时省略返回类型,在这种情况下, getint(int *);
would mean the same thing as int getint(int *);
与int getint(int *);
含义相同int getint(int *);
, because if you specified no return type it would default to int
. ,因为如果您未指定返回类型,则默认为int
。 It was however bad practice to do so even back in 1990. 但是,即使在1990年,这样做也是一个坏习惯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.