fuhsnn / slimcc

C11 compiler with GNU extensions for x86-64 Linux, working towards C23
MIT License
34 stars 4 forks source link

offsetof() should be a constant expression #23

Closed fuhsnn closed 11 months ago

fuhsnn commented 11 months ago

Per n1548 7.19-3:

offsetof ... expands to an integer constant expression that has type size_t

#include <stddef.h>
struct S { float f; int i; };
int arr [offsetof(struct S, i)];
int sz = sizeof arr;

chibicc sees arr as VLA and crashes at sz trying to resolve the size.