Topic: Function prototypes


Author: Jack Klein <jackklein@spamcop.net>
Date: Tue, 25 Sep 2001 16:46:40 GMT
Raw View
On Mon, 24 Sep 2001 17:10:08 GMT, kmalloc@hotmail.com (kmalloc) wrote
in comp.std.c++:

> Hello everyone!
>
> When I was first taught C, I was told that every function must have a
> prototype. Is this stated by the Standard? If so, is it so in C++ as
> well?
>
> Regards,
>
> kmalloc
>

C does not require function prototypes or even function declarations
if the function meets certain requirements, basically that it returns
an int and that you call it with arguments that (after the default
conversions, if any) exactly match the number and types of arguments
that the function takes.

Since the 1999 update to C, all functions require at least a
declaration, but prototypes are still not required for functions
accepting a fixed number of arguments if the conditions above are met.

C++ requires full function prototypes, specifying both the return type
and the number and types of all arguments.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Wed, 26 Sep 2001 00:37:13 GMT
Raw View
In article <bf40rt00nrdckoab108jnjks876soousil@4ax.com>, Jack Klein
<jackklein@spamcop.net> writes
>C++ requires full function prototypes, specifying both the return type
>and the number and types of all arguments.

Being pedantic, I believe that C++ only has function declarations (it
has no need for the word prototype because it has only a single form of
declaration, unlike C which needed a second term to distinguish between
K&R style declarations and fully typed declarations) However I note that
the standard does talk about prototype scope (which I think should now
be function declaration scope, I do not think it is worth a DR)


Francis Glassborow
I offer my sympathy and prayers to all those who are suffering
as a result of the events of September 11 2001.

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: "glancaster" <glancaster@ntlworld.com>
Date: Wed, 26 Sep 2001 16:25:12 CST
Raw View
Jack Klein:
> >C++ requires full function prototypes, specifying both the return type
> >and the number and types of all arguments.

Francis Glassborow:
> Being pedantic, I believe that C++ only has function
> declarations (it has no need for the word prototype
> because it has only a single form of declaration, unlike
> C which needed a second term to distinguish between
> K&R style declarations and fully typed declarations)
> However I note that the standard does talk about
> prototype scope (which I think should now be function
> declaration scope, I do not think it is worth a DR)

And bear in mind that a function definition is one kind
of function declaration. Thus you can write:

void foo()
{
    // ...
}

and subsequently call foo without a separate prototype.
But you still can't call foo before the point of its first
declaration.

This is generally considered bad form for "normal"
functions, but is quite common for inline functions and
function templates.

Kind regards

Garry Lancaster
Codemill Ltd
Visit our web site at http://www.codemill.net

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: kmalloc@hotmail.com (kmalloc)
Date: Mon, 24 Sep 2001 17:10:08 GMT
Raw View
Hello everyone!

When I was first taught C, I was told that every function must have a
prototype. Is this stated by the Standard? If so, is it so in C++ as
well?

Regards,

kmalloc

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Mon, 24 Sep 2001 21:11:35 GMT
Raw View
In article <fa1faa6a.0109231009.47ead9eb@posting.google.com>, kmalloc
<kmalloc@hotmail.com> writes
>When I was first taught C, I was told that every function must have a
>prototype. Is this stated by the Standard? If so, is it so in C++ as
>well?

you got it the wrong way round. C++ requires function declarations
(because overloading)



Francis Glassborow
I offer my sympathy and prayers to all those who are suffering
as a result of the events of September 11 2001.

---
[ 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.research.att.com/~austern/csc/faq.html                ]





Author: Mike Schilling <mike.schilling@ebay.sun.com>
Date: Tue, 25 Sep 2001 11:29:54 GMT
Raw View
kmalloc wrote:
>
> Hello everyone!
>
> When I was first taught C, I was told that every function must have a
> prototype. Is this stated by the Standard? If so, is it so in C++ as
> well?
>
If I say that "In C++, every function must have a prototype", I'm
quoting the Standard.
Prototypes are inescapable, like gravity.

If I say that "In C, every function must have a prototype", I'm giving
you excellent advice. Prototypes are not strictly required, but are a
very good idea, like not rollerblading on a freeway.

---
[ 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.research.att.com/~austern/csc/faq.html                ]