我已经尝试了 * 和 & 的所有可能的组合。我无法弄清楚这个程序出了什么问题以及是什么导致了这个编译时错误
我收到此错误:
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;
}
函数原型(prototype)为:
int function(unsigned int a, unsigned short *const b,
unsigned int *const c,
unsigned short *const d,
unsigned short *const e);
该函数是空的,我只是想用输入文件来编译它。
最佳答案
这些变量是指针,您尝试为它们分配整数(短)值:
unsigned short *a = (short) 89;
unsigned int *p =(int) 1;
unsigned short *q = (short) 10;
unsigned short *s = (short) 29;
这就是您收到编译器错误的原因。
问题不是 100% 清楚,但也许这就是您想要的:
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);
关于c - 初始化使指针来自整数而不进行强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46480290/