EDIT: apparently some of this isn't allowed/has changed in various C standards. For my own hypothetical benefit, let's pretend we're using gcc test.c
with no standard or warning options.
In particular I'm looking at the under-the-hood specifics. I've added my current understanding. Am I right?
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
is there some other difference between these two cases I'm not aware of (besides sizeof)?
struct a {
int i;
char c[0]; //sizeof(a) is sizeof(int)? a.c == (&i)+1?
};
As I understand it, this is typically used for variable length arrays at the end of structures. But what about
struct b {
char *c[0] //sizeof(b) is 0? where does c point?
};
int j;
struct b myb; //myb.c == (&j)+1 == $esp?
Furthermore, how is the address of a zero length array known if space for its pointer is never allocated anywhere? I suppose the same way a regular array's address is known, but I'm struggling to wrap my mind around it at the moment.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…