R
Rob Somers
Hey people,
I read a good thread on here regarding the reason why we use function
prototypes, and it answered most of my questions, but I wanted to
double check on a couple of things, as I am writing something up on
functions, and I don't like writing about things I am not sure about.
Ok, then, here we go:
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. So
this makes me wonder if I was wrong in thinking that I did not have to
use a prototype for a function returning an int. And now that I think
about it, 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 I am still relatively new to C) So the
question is this: 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 am not trying to
start flames here BTW, if this is potential flame material - I am
simply looking for your thoughts, as I really don't know that much
about the subject. Thanks
Rob Somers
I read a good thread on here regarding the reason why we use function
prototypes, and it answered most of my questions, but I wanted to
double check on a couple of things, as I am writing something up on
functions, and I don't like writing about things I am not sure about.
Ok, then, here we go:
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. So
this makes me wonder if I was wrong in thinking that I did not have to
use a prototype for a function returning an int. And now that I think
about it, 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 I am still relatively new to C) So the
question is this: 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 am not trying to
start flames here BTW, if this is potential flame material - I am
simply looking for your thoughts, as I really don't know that much
about the subject. Thanks
Rob Somers