我是 C 编程新手。我尝试创建一个小而简单的程序来从文件 calculs.x 中添加两个整数
这里,文件calculs.x的内容
/* calculs.x*/
struct data_in {
int arg1;
int arg2;
};
typedef struct data_in data_in;
struct result_int {
int result;
int errno;
};
struct result_float {
int result;
int errno;
};
typedef struct result_int result_int;
typedef struct result_float result_float;
program CALCULS{
version VERSION_UN{
void CALCULS_NULL(void) = 0;
result_int ADD (data_in) = 1;
result_int SUB(data_in) = 2;
result_int MUL(data_in) = 3;
result_float DIV (data_in) = 4;
} = 1;
} = 0x20000001;
我第一次为客户创建了一个文件 calculs.c:
#include <rpc/rpc.h>
#include "calculs.h"
int main(int argc, char *argv[]) {
int buffer[256];
struct data_in input;
struct result_int *output;
CLIENT *cl;
if (argc != 2) {
printf("usage: client hostname_of_server\n");
exit(1);
}
/*Etablir le lien vers le serveur distant
* cl = clnt_create(server, PROG, VERS, prot);
*/
cl = clnt_create(argv[1], CALCULS, VERSION_UN, "tcp");
if (cl == NULL) {
clnt_pcreateerror(argv[1]);
exit(1);
}
input.arg1 = 5;
input.arg2 = 5;
output = add_1(&input, cl);
if (output == NULL) {
clnt_perror(cl, argv[1]);
exit(1);
}
printf("the result field is %d\n", output->result);
printf("the errno field is %d\n", output->errno);
clnt_destroy(cl);
return 0;
}
我没有收到任何错误编译这个文件,但是对于另一个 rcalculs.c 文件,我无法编译。这是文件内容rcalculs.c:
#include <rpc/rpc.h>
#include "calculs.h"
result_int *add_1(struct data_in data, struct svc_req *rqstp) {
int buffer;
struct result_int result;
int a = data.arg1;
int b = data.arg2;
buffer = a+b;
result.result = buffer;
result.errno =0;
return result;
}
编译的消息错误是
rcalculs.c:11:13: erreur: conflicting types for ‘add_1’
In file included from rcalculs.c:9:0:
calculs.h:46:22: note: previous declaration of ‘add_1’ was here
rcalculs.c: In function ‘add_1’:
rcalculs.c:19:5: erreur: incompatible types when returning type ‘struct result_int’ but ‘struct result_int *’ was expected
你能帮我解决这个问题吗?