This is an old, obsolete syntax for declaring the type of the parameters of a function. You declare the types of the parameters after the line that contains the name of the function and its parameters, but before the opening brace that starts the body of the function.
compile(s)
char *s;
{
/* function body goes here */
}
The reason for this weird syntax is that it evolved from B, a predecessor of C, which did not have any type declarations: a variable was a machine word (a “cell”), and it was up to the programmer to use it correctly. See “The Problems of B” in “The Development of the C language” by Dennis Ritchie. With no types, to define a function, you'd just write
compile(s)
{
/* function body goes here */
}
In early C, parameter declarations were optional, so existing code kept working. If something's type wasn't declared, it defaulted to int
.
This declaration syntax is part of the first version of the C language, called K&R C after the authors of the seminal book about C, Brian Kernighan and Dennis Ritchie. In the late 1980s and 1990s, there was a gradual move to a newer version of the language called ANSI C or C89 or C90 (1989 and 1990 are the years the ANSI and ISO standards specifying the new version of the language came out). One of the main changes of ANSI C was in how function parameters are declared. In post-1990 C, you declare the type of parameters directly inside the parentheses, and you also declare the return type of the function (this is mandatory since C99, although many compilers still assume int
if the return type is omitted).
int compile(char *s)
{
/* function body goes here */
}