- 论坛徽章:
- 0
|
主要是维护方便:
如果不用头文件在a_call_tst_.c b_call_tst_.c中,
采取直接声明的 struct bbb_s,如果struct bbb_s 变动的话,将来要修改多份副本!
如果用头文件就直接修改头文件好了!
很大,很黄,很暴力!
tst.h
struct bbb_s
{
int x;
};
typedef struct bbb_s bbb_t;
tst.c
#include "tst.h"
int add(bbb_t a, bbb_t b )
{
int z;
z =a.x + b.x;
return z;
}
a_call_tst_.c
#if 0
struct bbb_s
{
int x;
};
typedef struct bbb_s bbb_t;
#endif
#include "tst.h"
int a_add(int x, int y)
{
bbb_t a,b;
a.x = x;
b.x =y;
return add(a,b);
}
b_call_tst_.c
#if 0
struct bbb_s
{
int x;
};
typedef struct bbb_s bbb_t;
#endif
#include "tst.h"
int b_add(int x, int y)
{
bbb_t a,b;
a.x = x;
b.x = y;
return add(a,b);
}
main.c
#include<stdio.h>
int main()
{
printf("sum of a_add %d \r\n",a_add(10,10));
printf("sum of b_add %d \r\n",b_add(20,20));
return 1;
}
makefile:
result:main.o
cc main.o a_call_tst_.o b_call_tst_.o tst.o -o result
main.o:a_call_tst_.o b_call_tst_.o
cc -c main.c
a_call_tst_.o: tst.o tst.h
cc -c a_call_tst_.c
b_call_tst_.o: tst.o tst.h
cc -c b_call_tst_.c
tst.o:tst.c tst.h
cc -c tst.c
clean:
rm -rf *.o
[ 本帖最后由 ronghuahan 于 2008-1-11 12:05 编辑 ] |
|