我有一段看似无辜的代码:
void generate_heightmap(float **terrain) {
}
int main(int argc, char **argv) {
float terrain[1500][1500];
generate_heightmap(terrain);
return 0;
}
但是当我尝试编译它时出现这些奇怪的错误,这可能是什么原因造成的?
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 ===|
我有 GCC 4.6.1 和 Ubuntu 11.11 64 位。
最佳答案
二维数组与双指针不兼容(考虑二维数组在内存中的布局方式,以及如何对其进行索引需要了解其中一个维度)。
这个精确的主题在 Question 6.18 中处理。 C 常见问题解答。
关于c - 奇怪的不兼容指针类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9344478/