我正在用C和汇编做一些东西,但当我在main中调用iesimo时,我得到了以下错误。
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
typedef struct nodo_t{
long dato;
struct nodo_t *prox;
} nodo;
typedef struct lista_t{
nodo* primero;
} lista;
extern int iesimo(lista* l, unsigned long i);
int main(int arg, char* argv[]) {
lista l;
nodo* n1 = malloc(sizeof(nodo));
n1->dato = 123;
n1->prox = NULL;
l.primero = n1;
nodo* n2 = malloc(sizeof(nodo));
n2->dato = 456;
n2->prox = NULL;
n1->prox = n2;
nodo* n3 = malloc(sizeof(nodo));
n3->dato = 78;
n3->prox = NULL;
n2->prox = n3;
nodo* n4 = malloc(sizeof(nodo));
n4->dato = 78;
n4->prox = NULL;
n3->prox = n4;
int response = iesimo((lista*) l, 2);
assert(response == 456);
return 0;
}
main.c:35:5: error: cannot convert to a pointer type
int response = iesimo((lista*) l, 2);
In assembly function, I return a long type.I wanna know what is the solution for this problemThanks !
int response = iesimo((lista*) l, 2);
而不是将传递的参数 l
的指针。lista
,你需要使用安培运算符。&
获取地址 l
:
int response = iesimo(&l, 2);