Home:ALL Converter>Terminology: Forward Declaration versus Function Prototype

Terminology: Forward Declaration versus Function Prototype

Ask Time:2011-12-14T05:18:03         Author:Andrew Cottrell

Json Formatter

To me these terms are essentially synonymous when using the C programming language. In practice I might prefer "forward declaration" for in-file prototypes versus "function prototype" for prototypes included via a header file. But even that is an artificial distinction when you consider what happens after preprocessing. Perhaps I'm missing something.

Is there a consensus for when to use one term versus the other?

Author:Andrew Cottrell,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/8496284/terminology-forward-declaration-versus-function-prototype
John Bode :

The term \"prototype\" refers to a specific declaration syntax; specifically, that the number and types of parameters to the function appear in the declaration. Given a function definition of\n\nint foo(int a, char *b) {...}\n\n\nyou can have any of the following declarations:\n\nint foo(); // a declaration, but not a prototype\nint foo(a, b); // a declaration, but not a prototype\nint foo(int, char *); // a declaration and a prototype\nint foo(int a, char *b); // a declaration and a prototype\n",
2011-12-13T22:17:54
greydet :

IMO those are not really synonyms.\nTo me \"function prototype\" refer to the function name and its parameters' and return's types. It does not only apply to what you call \"forward declaration\". All functions have a prototype.\n\nWe more often make a difference between a function declaration and its corresponding definition.",
2011-12-13T21:29:00
Fred Foo :

I use the term forward declaration for the following kind of struct declaration with a definition.\n\nstruct Foo;\n\n\nA function declaration need not be a full prototype, for compatibility with pre-1989 (K&R) C.\n\nchar *foo(); // NOT the same as char *foo(void)\n",
2011-12-13T21:21:49
Patrick Schlüter :

The only concept in C I'm aware of is the distinction between declaration and definition. A prototype is a declaration and can happen anywhere, anytime and the definition which is the actual implementation od the given object. by that concept, there is no thing called forward declaration, ther's only an order of declaration.",
2011-12-13T21:23:53
yy