Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
diohabara committed Jul 18, 2023
1 parent 628d267 commit 9cd1681
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,13 @@ VarList *read_func_param() {
ty = declarator(ty, &name);
ty = type_suffix(ty);

/* "array of T" is converted to "poitner to T" only in the parameter context.
* For example, *argv[] is converted to **argv by this.
*/
if (ty->kind == TY_ARRAY) {
ty = pointer_to(ty->base);
}

Var *var = push_var(name, ty, true, tok);
push_scope(name)->var = var;

Expand Down
4 changes: 4 additions & 0 deletions tests
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ int count() {
return cnt;
}

int param_decay(int x[]) { return 0[x]; }

int main() {
assert(8, ({
int a = 3;
Expand Down Expand Up @@ -777,6 +779,8 @@ int main() {
assert(0, (2-2)&&5, "(2-2)&&5");
assert(1, 1&&5, "1&&5");

assert(3, ({ int x[2]; x[0]=3; param_decay(x); }), "int x[2]; x[0]=3; param_decay(x);");

printf("OK\n");
return 0;
}

0 comments on commit 9cd1681

Please sign in to comment.