c - 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 类型。我想知道这个问题的解决方案是什么谢谢!
解决方案
int response = iesimo((lista*) l, 2);
无需将传递的参数l
转换为指向 的指针lista
,您需要使用 & 运算符&
来获取 的地址l
:
int response = iesimo(&l, 2);
推荐阅读
- android - 如何使用 material.BottomNavigationView 设置 Jetpack 导航
- maven - 无法在网页上检索新图像
- javafx - Javafx KeyEvent 不会使用 Enter 按钮
- c++ - 在“操作码”中出现错误内联汇编语法错误;发现“常数”
- arrays - 如何使用数组创建 2D 圆柱体
- python - 使用不断变化的 Xpath 查找元素
- node.js - 将 greenlock-express 与 Web 套接字一起使用
- python - QSqlDatabase:未加载 QMYSQL 驱动程序 PyQt5 Python 3.6
- android - 我应该尽可能使用 Recyclerview 吗?
- php - 除了在 wordpress 中的日期之外,如何显示博客发布时间?