C 错误数组 : array type has incomplete element type.

标签 c arrays

我有:

extern int docx(char *,char[][]) // in a header file

在solaris下编译正常,但在Redhat Linux下显示如下错误:

array type has incomplete element type.

我知道我可以将其解决为 - char[][20]

这是正确的方法吗?

最佳答案

您必须知道该功能实际需要什么,并相应地修改界面。如果它需要一个二维数组 (char [N][M]),正确的接口(interface)应该是:

extern int docx(char *,char*[M]);

区别于:

extern int docx( char*, char** );

在第一种情况下,该函数需要指向包含 N*M 个字符的连续内存块的指针(&p[0][0]+M == &p[ 1][0](void*)&p[0][0]==(void*)&p[0]),而在第二种情况下,它将期待一个指向包含 N 的内存块的指针 指向可能连续或不连续的内存块的指针(&p[0][0]&p[1] [0]p[0]==&p[0][0])

无关
// case 1
ptr ------> [0123456789...M][0123.........M]...[0123.........M]

// case 2
ptr ------> 0 [ptr] -------> "abcde"
            1 [ptr] -------> "another string"
              ...
            N [ptr] -------> "last string"

关于C 错误数组 : array type has incomplete element type.,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2468214/

相关文章:

c - x86_64 : forcing gcc to pass arguments on the stack

c - 丢失的字母去哪儿了?

javascript - 给定一个范围,找到数组中缺失的数字

javascript - 在 Knockout 可观察数组订阅函数中,你能确定添加或删除了哪些元素吗?

python - 如何使用 np.where() 创建特定行的新数组?

c - 原始套接字监听器

c - 如何使用PIC18在 Debug模式下模拟中断?

c - Malloc ~ 段错误 C

c - 将数组作为参数传递并交换数据 - 意外数据

arrays - 混合数字和文本时出现意外的 COUNTIF 行为 (EXCEL)