R
Roy Hills
I've seen two different function prototype formats used for ANSI C,
and I'm unsure as to which is the correct or preferred one.
1st Format (this is what I use)
type function(type, type, type);
e.g. "int multiply(int, int);"
2nd Format (I've seen this used in other people's code)
type function(type param, type param);
e.g. "int multiply(int first, int second);"
So the first format just gives the types, whereas the second format
gives the parameters as well. The second format is just re-stating
the function declaration.
I currently use the first format, and it works on many different C
compilers. I've also seen the second format used in other code, and
that works fine, with GCC at least.
I typically use GCC, but it's important that my code work on other
compilers as well as I maintain code which needs to be portable. My
code is ANSI C; I'm not concerned with C++.
I can't see this mentioned in the FAQ, although it would seem to be an
obvious question (to me at least). Apologies if the answer is equally
obvious.
Roy
and I'm unsure as to which is the correct or preferred one.
1st Format (this is what I use)
type function(type, type, type);
e.g. "int multiply(int, int);"
2nd Format (I've seen this used in other people's code)
type function(type param, type param);
e.g. "int multiply(int first, int second);"
So the first format just gives the types, whereas the second format
gives the parameters as well. The second format is just re-stating
the function declaration.
I currently use the first format, and it works on many different C
compilers. I've also seen the second format used in other code, and
that works fine, with GCC at least.
I typically use GCC, but it's important that my code work on other
compilers as well as I maintain code which needs to be portable. My
code is ANSI C; I'm not concerned with C++.
I can't see this mentioned in the FAQ, although it would seem to be an
obvious question (to me at least). Apologies if the answer is equally
obvious.
Roy