getint (int *);
I am not really sure what does getint (int *)
mean? Can someone explain this?
This is a function prototype declaring the function getint()
. The function takes as pointer to an int
as a parameter.
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
. Omiting a return type however is violating the recent C standard, so code doing so could be considered invalid.
An equivalent to
getint(int *);
though would be
int getint(int * pi);
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
.
The recommended way to write is is to specify the return type explicitly, like
if int
, like
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 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)
If, in the declaration
'T D1'
,D1
has the formD( 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.
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 *);
would mean the same thing as int getint(int *);
, because if you specified no return type it would default to int
. It was however bad practice to do so even back in 1990.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.