/* * foo.h */ typedef struct _FOO * FOO ; typedef enum { FooEnumOk, FooEnumIll } FOO_ENUM ; extern FOO CreateFoo() ; extern FOO_ENUM UpdateFoo( FOO, int, int, int ) ; extern void PrintFoo( FOO ) ; extern void FreeFoo( FOO ) ; ======================================================== /* * foo.c */ #include "Foo.h" struct _FOO { int a ; int b ; int c ; } ; FOO CreateFoo( void ) { FOO foo ; foo = (FOO) malloc( sizeof(struct _FOO) ) ; if ( foo ) { foo->a = foo->b = foo->c = 0 ; } return foo ; } void PrintFoo( FOO foo ) { printf("%d %d %d\n", foo->a, foo->b, foo->c ) ; } void FreeFoo( FOO foo ) { free( foo ) ; } FOO_ENUM UpdateFoo ( FOO foo, int a, int b, int c ) { foo->a = a ; foo->b = a + b ; foo->c = a + b + c ; return FooEnumOk ; } ================================================= /* * bar.h */ typedef struct _BAR * BAR ; typedef enum { BarEnumOk, BarEnumIll } BAR_ENUM ; extern BAR CreateBar() ; extern BAR_ENUM UpdateBar( BAR, double, double, double ) ; extern void PrintBar( BAR ) ; extern void FreeBar( BAR ) ; ====================================================== /* * bar.c */ #include "Bar.h" struct _BAR { double a ; double b ; double c ; } ; BAR CreateBar( void ) { BAR bar ; bar = (BAR) malloc( sizeof(struct _BAR) ) ; if ( bar ) { bar->a = bar->b = bar->c = 0.0 ; } return bar ; } void PrintBar( BAR bar ) { printf("%f %f %f\n", bar->a, bar->b, bar->c ) ; } void FreeBar( BAR bar ) { free( bar ) ; } BAR_ENUM UpdateBar( BAR bar, double a, double b, double c ) { bar->a = a ; bar->b = a + b ; bar->c = a + b + c ; return BarEnumOk ; } ================================================= /* * FooBar.c */ #include #include "Foo.h" #include "Bar.h" int main ( int argc, char * argv() ) { FOO foo ; BAR bar ; foo = CreateFoo() ; bar = CreateBar() ; UpdateFoo( foo, 1, 2, 3 ) ; PrintFoo( foo ) ; FreeFoo( foo ) ; UpdateBar( bar, 1.0, 2.0, 3.0 ) ; PrintBar( bar ) ; FreeBar( bar ) ; }