首页 > 解决方案 > C - 汇编错误:无法转换为指针类型

问题描述

我正在用 C 和 assembly 做一些事情,但是当我在 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);

在汇编函数中,我返回一个 long 类型。我想知道这个问题的解决方案是什么谢谢!

标签: cfunctionpointersassemblyparameter-passing

解决方案


int response = iesimo((lista*) l, 2);

无需将传递的参数l转换为指向 的指针lista,您需要使用 & 运算符&来获取 的地址l

int response = iesimo(&l, 2); 

推荐阅读