The conventional way is to put declarations in a header file and definitions in a source file:
foo.h:
Code:
#ifndef FOO_H
#define FOO_H
// declarations
extern int myvariable;
int foo(int x);
#endif
foo.c:
Code:
#include "foo.h"
// definitions
int myvariable;
int foo(int x)
{
return x+5;
}
main.c:
Code:
#include <stdio.h>
#include "foo.h"
int main(void)
{
int y = foo(3);
printf("%d\n",y)
}
"extern" means "this object is declared here but defined elsewhere". It's usually used to declare variables in a header file. It's optional (that is, it's not needed) for function declarations.