I have a sample code that there is a function in it that is declared as
void _rt(void);
what type of function is "_rt"?
what dose underline mean before name of function?
CodePudding user response:
When you wrote:
void _rt(void);
Syntactically you're declaring a function named _rt
which takes no parameters and has a return type of void
.
But note that, names starting with two underscores are reserved for use by the language implementation. So you should not use names starting with double underscores in your program.
In your given program there is only a single underscore in _rt
and since identifiers beginning with an underscore are reserved in global namespace, you should also avoid the use of names with leading single underscore.
CodePudding user response:
what type of function is "_rt"?
The type of _rt
is void()
. The function returns void
and accepts no parameters.
what dose underline mean before name of function?
It's just part of the name of the function. Only the author who wrote it knows why they named the function the way that they did (unless they've documented that choice somewhere).
Note however that in the global namespace, names that begin with underscore are reserved to the language implementation. If that function is in the global namespace, then either it is internal to implementation and you shouldn't use it, or someone has made a mistake when they were giving the name for the function.
CodePudding user response:
The function type is void
, which means that the function doesn't return anything. Also, _
doesn't change anything, _rt()
still is a normal function. It's just a part of naming conventions. But 2 underscores (__
) does have a meaning. For more info on this, look up here.
CodePudding user response:
Is is _rt or __rt?
- the identifiers with a double underscore anywhere are reserved;
- the identifiers that begin with an underscore followed by an uppercase letter are reserved;
- the identifiers that begin with an underscore are reserved in the global namespace.
Identifiers and their special cases are explained in details here
By convention identifiers with an underscore and lowercase letter that aren't in a global namespace are used for private function that should not be used directly but need to be visible for some reason or another.
Best to avoid anything starting with an _.