相关疑难解决方法(0)

零长度数组与指针

编辑:显然其中一些不允许/已在各种C标准中发生变化.对于我自己的假设好处,让我们假装我们使用gcc test.c没有标准或警告选项.

特别是我正在研究引擎盖下的细节.我加入了目前的理解.我对吗?

char **c1;   //Size for a pointer is allocated on the stack. sizeof(c1) == sizeof(void*)
char *c2[0]; //Nothing is allocated on the stack.  sizeof(c2) == 0
Run Code Online (Sandbox Code Playgroud)

这两个我不知道的情况(除了sizeof)还有其他的区别吗?

struct a {
   int i;
   char c[0]; //sizeof(a) is sizeof(int)?  a.c == (&i)+1?
};
Run Code Online (Sandbox Code Playgroud)

据我了解,这通常用于结构末端的可变长度数组.但是关于

struct b {
   char *c[0] //sizeof(b) is 0?  where does c point?
};

int j;
struct b myb; //myb.c == (&j)+1 == $esp?
Run Code Online (Sandbox Code Playgroud)

如果零指针的地址从未在任何地方分配,那么零长度数组的地址如何知道呢?我认为常规数组的地址已知的方式相同,但我现在正在努力绕过它.

c arrays pointers

21
推荐指数
2
解决办法
8768
查看次数

标签 统计

arrays ×1

c ×1

pointers ×1