Skip to content

Commit b44dc57

Browse files
committed
Fix formatting, add testcase, remove static
1 parent a35da48 commit b44dc57

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

src/parser.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,15 +1319,16 @@ void parse_array_compound_literal(var_t *var,
13191319
break;
13201320
}
13211321
}
1322+
13221323
lex_expect(T_close_curly);
13231324
var->array_size = count;
13241325
}
1325-
static bool is_array_literal_temp(var_t *var)
1326+
bool is_array_literal_temp(var_t *var)
13261327
{
13271328
return var && var->array_size > 0 && var->var_name[0] == '.';
13281329
}
13291330

1330-
static var_t *scalarize_array_literal(block_t *parent,
1331+
var_t *scalarize_array_literal(block_t *parent,
13311332
basic_block_t **bb,
13321333
var_t *array_var,
13331334
type_t *hint_type)

tests/array_ptr.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdio.h>
2+
3+
int add(int a, int b)
4+
{
5+
return a + b;
6+
}
7+
8+
int main(void)
9+
{
10+
int *a = (int[]){1, 2, 3, 4, 5};
11+
12+
printf("Testing basic array compound literal:\n");
13+
for (int i = 0; i < 5; i++)
14+
printf(" a[%d] = %d\n", i, a[i]);
15+
16+
int sum = a[0] + a[4];
17+
printf("Sum = %d (expect 6)\n", sum);
18+
19+
int base = 50;
20+
int combined = base + (int[]){100, 200};
21+
printf("base + (int[]){100,200} = %d (expect 150)\n", combined);
22+
23+
int acc = 25;
24+
acc += (int[]){100, 200};
25+
printf("acc after += array literal = %d (expect 125)\n", acc);
26+
27+
int flag = 1;
28+
int ternary_val = flag ? (int[]){25, 50} : (int){15};
29+
printf("ternary true branch = %d (expect 25)\n", ternary_val);
30+
31+
flag = 0;
32+
ternary_val = flag ? (int[]){25, 50} : (int){15};
33+
printf("ternary false branch = %d (expect 15)\n", ternary_val);
34+
35+
int func_val = add((int){5}, (int[]){10, 20, 30});
36+
printf("add((int){5}, (int[]){10,20,30}) = %d (expect 15)\n", func_val);
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)