我是rpcgen的新手,我对C的知识不是最好的。对于我的项目,我需要使用链接列表,因为许多功能将从数据库到客户端检索数据列表。我已经实现并生成了代码“ lista.h”和“ lista.c”,其中分别包含函数的定义以及列表的结构和函数的代码。
在“ Linkder.x”中(Linkder是我的应用程序的名称),我已经定义了生成文件所需的所有内容,并包括了“ lista.h”。
问题是,当我使用rpcgen应用命令rpcgen -C -a Linkder.x
生成文件时,出现以下错误:
typedef long unsigned int size_t;
^^^^^^^^^^^^^^^^^^^^^
/usr/lib/gcc/x86_64-linux-gnu/7/include/stddef.h, line 216: expected '*' or 'identifier'
[当我使用文本编辑器打开stddef.h时,第216行显示以下内容:stddef.h
我不知道是什么导致了此错误。我已经测试了创建test.c文件的列表,并可以正常运行。当我使用malloc函数创建新节点时,此错误可能是由sizeof运算符引起的。
解决该错误的唯一方法是删除#include“ lista.h”和使用我的.x文件中的列表的每个函数。
这是我的代码:
/*Linkder.x*/
#include "estructuras.h"
#include "lista.h"
program Linkder {
version LINKDER_VER {
/*Funciones*/
tlista *listar_juegos() = 1;
tlista *recomendar_juegos() = 2;
void crear_usuario(struct usuario) = 4;
void juego_fav(struct datos_juego) = 5;
void borrar_juego(struct datos_juego) = 6;
tlista *obtener_usuario_juego(int) = 7;
tlista *obtener_juegos_fav(char[50]) = 8;
void login(struct usuario) = 9;
} = 1;
} = 1;
lista.h:
/*lista.h*/
#include <stdio.h>
#include <stdlib.h>
typedef struct nodo {
char nombre_juego[50];
char nick_jugador[50];
int id_juego;
struct nodo *next;
} tnodo;
typedef struct {
tnodo *head;
int size;
} tlista;
/*funciones*/
//void delete(tlista *l);
int getsize(tlista l);
int isempty(tlista l);
void insert(tlista *l, char c1[50], char c2[50], int num);
/*void view(tlista l);*/
void create(tlista *l);
lista.c:
#include <stdio.h>
#include <stdlib.h>
#include "string.h"
#include "lista.h"
int getsize(tlista l) {
return(l.size);
}
int isempty(tlista l) {
if(l.size == 0) {
return(1);
} else {
return(0);
}
}
void insert(tlista *l, char c1[50], char c2[50], int num) {
tnodo *aux;
if(isempty(*l)) {
l->head = (tnodo*)malloc(sizeof(tnodo));
strcpy(l->head->nombre_juego, c1);
strcpy(l->head->nick_jugador, c2);
l->head->id_juego = num;
l->head->next = NULL;
l->size++;
} else {
aux = l->head;
while(aux->next != NULL)
{
aux = aux->next;
}
aux->next = (tnodo*)malloc(sizeof(tnodo));
strcpy(aux->next->nombre_juego, c1);
strcpy(aux->next->nick_jugador, c2);
aux->next->id_juego = num;
aux->next->next = NULL;
l->size++;
}
}
void create(tlista *l)
{
l->head=NULL;
l->size=0;
}
rpcgen版本是2.27,gcc版本是7.5.0。我的操作系统是Ubuntu 18.04.4 LTS我已经在其他PC上测试过我的代码
提前感谢。
此答案表明在使用rpcgen时未定义unsigned long long。https://stackoverflow.com/a/43186591/10273360
我实际上不知道如何规避此错误,但是我可以告诉您错误即将来临,因为您已经包含了stdio.h and stdlib.h
头文件,而这些文件又将stddef.h包含在您自己的lista.h头中文件。
#include <stdio.h>
#include <stdlib.h>
而且碰巧,您可以删除这两个文件而没有任何问题,因为您的头文件不使用来自这两个头的任何功能。
这不是一个适当的解决方案或解释,但这是我可以告诉的。更像是伪解决方案。如果有经验的人可以在这里透露一些信息,那就太好了。