A couple of questions re. the function prototype

A

Alex

It's actually "non-prototype declaration" (or "old style declaration")
and "prototype declaration". Plain "declaration" means either of the two.

Indeed. That sounds more correct.

Alex
 
P

Paul Emmons

I initially thought that one would only really need to use a function
prototype if the type the function returned was not an int - I was
under the impression that if there was no prototype, the compiler
would assume it was an int. However, my compiler (gcc) squawks at me
if I do not use a prototype even if the function returns an int.

I've recently begun using gcc with the option -Wall, which makes it
squawk about a lot of other things, too, but I'm glad.
the prototype does more than allow the compiler to check for
a return type perhaps? It also allows for it to check that the
arguments at the function call are of the same type as the parameters
of the function?

Yes, and this is even more important IMHO. Without it, you could call
the function without even the correct number of parameters.
Is it proper (as regarding making portable
programs) to *always* use a function prototype? And then my second
question is, If the actual function serves as a prototype also, why
not just put all the functions before main()?

I've always put main() last for this reason: to avoid writing a
specific prototype for the functions in the same source file.
But otherwise, I wouldn't want to do without them. I started learning
C in the early 1980s, before the ANSI standard, and often had trouble
from calling functions with wrong arguments. Prototypes are a great
blessing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top