Topic: Do "function prototypes" really exist?
Author: kprateek88@yahoo.com (Prateek R Karandikar)
Date: Thu, 3 Jun 2004 17:28:44 +0000 (UTC) Raw View
Does the standard ever mention the phrase "function prototype"? Many
C++ books make a big fuss about "function prototypes". They use it in
the sense "function declaration that is not a definition". All names
must be declared before use, and some uses of some types of names need
a definition too. So what's so special about funcions? I know one
could call undeclared functions in C, and so functions were different,
but in C++ all names must be declared before use, so why fuss over
functions?
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: AlbertoBarbati@libero.it (Alberto Barbati)
Date: Thu, 3 Jun 2004 21:56:43 +0000 (UTC) Raw View
Prateek R Karandikar wrote:
> Does the standard ever mention the phrase "function prototype"? Many
> C++ books make a big fuss about "function prototypes". They use it in
> the sense "function declaration that is not a definition".
Strictly speaking, the term "function prototype" is C terminology, not
C++. It's defined in the C standard 6.2.1/2: "A function prototype is a
declaration of a function that declares the types of its parameters"
Such terminology makes sense in C as declarations like
int foo(); // a declaration, *not* a prototype
and
int foo(void); // a declaration that's a prototype
have very different meaning. In C++ there is no such difference, so we
can say that every function declaration is a prototype. Notice that this
also includes declarations that *are* definitions. The very common use
of the term "prototype" to identify "declarations that are not
definition" is thus not completely correct. (But I'm pretty sure I must
have used this incorrect terminology several times myself... ;)
BTW, a full-text search in the C++ reveals that the word "prototype" is
used exactly 10 times (you did try to do a search before asking, right? ;)
Apart from three occurrences in the index and three references to C
prototypes, the word is used in 3.3.3 to define the concept of
"function-prototype-scope". Such concept is indeed related only to
declarations that are not definitions, but only because function
definitions trigger the broader concept of local-scope described in 3.3.2.
There is finally a reference to "function prototype" in 17.3.1.3/1, but
as the term has never been defined, it's probably a misprint.
> All names
> must be declared before use, and some uses of some types of names need
> a definition too. So what's so special about funcions? I know one
> could call undeclared functions in C, and so functions were different,
> but in C++ all names must be declared before use, so why fuss over
> functions?
Remember that in C++ functions may be overloaded. The presence and/or
absence of an overloaded function declaration (==prototype!) before the
actual use of the function's name does matter.
Alberto
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]