mirror of
https://github.com/rui314/chibicc
synced 2024-11-22 22:31:18 +03:00
Add flexible array member
This commit is contained in:
parent
3d216e3e06
commit
824543bb2f
6
parse.c
6
parse.c
@ -1706,6 +1706,12 @@ static void struct_members(Token **rest, Token *tok, Type *ty) {
|
||||
}
|
||||
}
|
||||
|
||||
// If the last element is an array of incomplete type, it's
|
||||
// called a "flexible array member". It should behave as if
|
||||
// if were a zero-sized array.
|
||||
if (cur != &head && cur->ty->kind == TY_ARRAY && cur->ty->array_len < 0)
|
||||
cur->ty = array_of(cur->ty->base, 0);
|
||||
|
||||
*rest = tok->next;
|
||||
ty->members = head.next;
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ int main() {
|
||||
ASSERT(8, sizeof(int(*)[10]));
|
||||
ASSERT(8, sizeof(int(*)[][10]));
|
||||
|
||||
ASSERT(4, sizeof(struct { int x, y[]; }));
|
||||
|
||||
printf("OK\n");
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user