简体   繁体   中英

C - Assembly error: cannot convert to a pointer type

I am making some things with C and assembly, but when I call iesimo in main, I obtain the following error:

    #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 problem Thanks !

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

Instead of casting the passed argument l to a pointer to lista , you need to use the ampersand operator & to obtain the address of l :

int response = iesimo(&l, 2); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM