In the code you listed, the functions before main
are function prototypes, also called function declarations (they are synonyms). They are not function calls. You can tell they aren't function calls for two reasons:
- Functions cannot be called from the global scope. The global scope is anything outside of a function body. This is the quickest way to recognize it, but it's a little hand wavy.
- The real reason is that function calls are not preceded by type specifiers or type qualifiers, like
void
andstatic
. These keywords specify the type of a symbol, in this case the function being declared. Function calls don't have a type (the return value does, but not the call itself), so you would never specify the type this way for a function call.
To answer some of your other questions:
- In most implementations (and according to the C standard) the first user defined function to be executed is always
main
, in which case it is not possible for you to write code that calls any other function before main. In most cases, compilers will generate their own initialization code which is executed before your main function. It does things like set up memory and initialize static variables. In some cases, you can write code that will be used as part of initialization, but that's relatively uncommon and it would be compiler specific how to do that. - A function prototype, or function declaration, is just a way of telling the compiler about a function before you actually define/implement it. The declaration/prototype (same thing) tells the compiler: a) this symbol is a function, b) it has such-and-such return type, c) it has such-and-such parameter list. That way, when the compiler sees you try to call the function somewhere else in your code, it knows what you're trying to do.
- The
static
keyword is called a storage specifier. On functions, it simply means that the function name is not exported to the linker, so it cannot be called from any other code modules (i.e., from any other C source files). So it's really just a way of limiting the visibility, or the scope, of the function. - Remember, a header file is just a way to include the same content in multiple places. Anywhere you
#include
a file, the compiler will treat it as if the contents of the included file appeared directly in the spot where it is included from. So function prototypes/declarations will very often appear in a header file. This allows the function to be "known" (and therefore called) from any source file where the header is included. Function implementations (also called function definitions) should generally not be put in header files. Doing so would cause the function to be defined every time the file is included, which will generally cause the linker to complain that the name (of the function) has multiple definitions. (The only way to get around that is marking the functionstatic
, and then you're really defining a file-local function each time the header is included, as opposed to implementing a single function with global scope which can be called from multiple source files. The latter is usually what you want.)