Possible Duplicate:
C function syntax, parameter types declared after parameter list
I saw the following syntax for function definition in "Expert C Programming"
int compare(s1, s2)
char * s1, *s2;
{
while (*s1++ == *s2) {
if (*s2++ == 0) return (0);
}
return (*--s1 - *s2);
}
How is the above definition valid? It compiles and runs perfectly without any errors.
I am more comfortable with the following syntax for function definition
int compare(char * s1,char *s2)
{
while (*s1++ == *s2) {
if (*s2++ == 0) return (0);
}
return (*--s1 - *s2);
}
and no where I've seen the one given in the book(While studying C in my college or elsewhere), can anyone please throw some light on the one given in the book.
This topic has been discussed here before, it's the "Kernighan and Ritchie style" of function definition.
Nowadays you should prefer the second syntax, the first one is still accepted by some compilers for backwards compatibility reasons but it should be considered deprecated for all practical purposes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With