c - 奇怪的不兼容指针类型错误

标签 c types

我有一段看似无辜的代码:

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/

相关文章:

c - 释放链表中的节点

c - 需要帮助了解位重置功能

sql - 对于将被连接、 "LIKE' d"并进行大量查询的文本字段,我应该使用什么 SQL Server 数据类型?

java - 数据表示和存储——人的年龄

c - 使用 lpddr2 启动 sama5d2

我可以在图表的边缘插入数据吗?

c - C 中的文件处理

.net - SqlDateTime.MinValue != DateTime.MinValue,为什么?

C++ 将变量类型传递给函数

c# - 创建可用作函数/方法的类型