我试过*和&的每个可能的组合。我想不出有什么不对这个程序,是什么原因造成这个编译时错误初始化使指针从整数没有演员
我得到这个错误:
error: initialization makes pointer from integer without a cast
compilation terminated due to -Wfatal-errors.
有了这个代码:
int main() {
unsigned int ten = (int) 10;
unsigned short *a = (short) 89;
unsigned int *p =(int) 1;
unsigned short *q = (short) 10;
unsigned short *s = (short) 29;
function(ten,a,p, q, s);
return 0;
}
的函数原型是:
int function(unsigned int a, unsigned short *const b,
unsigned int *const c,
unsigned short *const d,
unsigned short *const e);
该函数是空的,我只是想让它用inp编译ut文件。
您可以调用function(),但只显示decode_instruction()的原型。请显示您遇到问题的代码。 – torstenvl
此外,您必须取消引用指针以将值分配给它指向的内存位置。此外,如果你没有先分配内存,那是未定义的行为。为什么main()中的局部变量定义为指针而不是变量? – torstenvl
不仅定义为指针,而且用整数初始化。你不能在初始化器中取消引用指针......你只能初始化指针本身,然后你可以通过它来分配(假设你已经给出它的内存)。 –