What is the difference between a declaration and a prototype in C? In what situations are they called declarations and in what prototypes?
TL DR; . All prototypes are declarations, but not all declarations are prototypes.
A declaration is a general terminology used in standards; a prototype is more specific.
Quote C11, chapter §6.7
C11
An ad defines the interpretation and attributes of a set of identifiers. [...]
and from §6.7.6,
, , , , , , .
, §6.2.1
[....] prototype - , .
, , - ( ) .
"": §6.4.2.1,
( _, ) , , 6.2.1. [...]
_
§6.2.1,
; ; , ; typedef; ; ; . [....]
:
int a; // "a" has type int
( ) :
int f(); // a function call expression "f(x, y, ...)" has type int
, ; , . ( ):
int g1(void); // "g1" takes no arguments, "g()" has type int int g2(float, char); // "g2" takes two arguments int g3(int, ...); // "g3" takes at least one argument
, : , . , , ( , - ).
, , "" : int g2(); int g2(float, char) { return 0; }, g2 , - . , .
int g2();
int g2(float, char) { return 0; }
g2
, , , (...). <stdarg.h> , -.
...
<stdarg.h>
- , ;.
;
- , .
, : void func (void);: - : void func ();.
void func (void);
void func ();
- (6.11.6), C. .
C (6.2.1 )
... ( - , .)
.
, ,
void f();
void f( void );
The first declaration is not a prototype, because nothing is known about the parameters of the function.
The second declaration is a prototype because it provides a list of function parameter types (this is a special type of type list that indicates that the function has no parameters).
Source: https://habr.com/ru/post/1676353/More articles:Facebook together with user parameters with API version 2.9 - facebookIs there any difference between waiting for the last asynchronous call and just returning it? - c #ORACLE: quick update on a materialized view that does not work with OUTER JOIN in some conditions - sqlCalculate status bar height / actual browser height in Android browser using pure javascript? - javascriptЧто делает оператор ^ = в Perl? - perlReturn an empty array instead of null - c #AWS RDS retention period longer than specified in instance settings - amazon-rdswhy do we need to do a side check for google recaptcha? - spring-bootIs this clojure.core.match error or is it just me? - pattern-matchingHow to find all matches in a string - c #All Articles