奇怪的不兼容指针类型错误 [英] Weird incompatible pointer type error
本文介绍了奇怪的不兼容指针类型错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这段看似无辜的代码:
void generate_heightmap(float **terrain) {}int main(int argc, char **argv) {浮动地形[1500][1500];生成高度图(地形);返回0;}
但是当我尝试编译它时出现了这些奇怪的错误,这可能是什么原因?
test.c||在函数‘main’中:|test.c|8|警告:从不兼容的指针类型传递generate_heightmap"的参数 1 [默认启用]|test.c|1|注意:预期为float **",但参数类型为float (*)[1500]"|||=== 构建完成:1 个错误,1 个警告 ===|
我有 GCC 4.6.1 和 Ubuntu 11.11 64 位.
解决方案
二维数组与双指针不兼容(考虑二维数组在内存中的布局,以及索引它需要了解尺寸).
C 常见问题解答的问题 6.18 处理了这个确切的主题.>
I have this seemingly innocent piece of code:
void generate_heightmap(float **terrain) {
}
int main(int argc, char **argv) {
float terrain[1500][1500];
generate_heightmap(terrain);
return 0;
}
But when I try to compile it I get these weird errors, what could be the cause of this?
test.c||In function ‘main’:|
test.c|8|warning: passing argument 1 of ‘generate_heightmap’ from incompatible pointer type [enabled by default]|
test.c|1|note: expected ‘float **’ but argument is of type ‘float (*)[1500]’|
||=== Build finished: 1 errors, 1 warnings ===|
I have GCC 4.6.1 and Ubuntu 11.11 64bit.
解决方案
A 2D array is not compatible with a double pointer (consider how a 2D array is laid out in memory, and how indexing into it requires knowledge of one of the dimensions).
This precise topic is dealt with at Question 6.18 of the C FAQ.
这篇关于奇怪的不兼容指针类型错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文