a.c
#include<stdio.h>
#include "a.h"
int main(){
s.a = 10;
printf("\n add : %d \n",add(2,2));
printf("\n sub : %d \n",sub(2,2));
printf("\n struct is : %d \n",s.a);
return 0;
}
b.c:
#include<stdio.h>
int add(int a,int b){
return (a+b);
}
int sub(int a,int b){
return (a-b);
}
a.h:
#ifndef A_HEADER
#define A_HEADER
typedef struct _s{
int a;
int b;
}s;
int add(int a,int b);
int sub(int a,int b);
#endif
O / P:
[root@s new]# ls
a.c a.h b.c include
[root@s new]# gcc -c a.c -o a.o
a.c: In function ‘main’:
a.c:4: error: expected identifier or ‘(’ before ‘.’ token
a.c:7: error: expected expression before ‘s’
我上面收到了一个错误 . 找不到错误的原因
2 回答
s
是一种类型 - 您需要声明此类型的实例:你使
s
在ah.h中使用typedef
作为类型说明符并做
用点东西