Syntax: |
|
filename.h: |
Module interface |
return_type function_name2( type arg1, type arg2, ... );
extern type variable2; /*external declaration*/ |
Public function prototype
External declaration |
filename.c: |
|
#include <filename2.h> #include "filename.h"
type variable1; type variable2;
return_type function_name1( type arg1, type arg2, ... );
main( ) { : return 0; }
return_type function_name1( type arg1, type arg2, ... ) { : return expression; }
return_type function_name2( type arg1, type arg2, ... ) { : return expression; }
|
Header files
Module variables definitions
Local function prototype
Main function - start running here.
Module function |
Example: |
|
my_module.h: |
|
typedef enum days { sunday, monday, tusday } T_DAY;
#define NUM 100 extern T_DAY x[NUM];
/* Module's interface functions - to be called from other modules */ void Set_X(); void Get_X(); |
|
my_module.c: |
|
#include <stdio.h> #include "my_module.h"
T_DAY x[NUM]; int n; char c;
int Calc_X();
void Set_X() { ... }
void Get_X() { ... }
int Calc_X() { ... } |
|
main.c: |
|
#include <stdio.h> #include "my_module.h"
main() { int x;
Set_X(); x = Get_X();
printf("x value=%d", x); return 0; } |