fuhsnn/slimcc

Global variable wrongly initialized with const-copy/compound-literal

Closed this issue · 0 comments

#include <stdio.h>
int x;
struct S {
    int i, *p;
};

const struct S s1 = {3, &x};
struct S s2 = s1;
struct S s3 = (struct S){9, &x};

int main(void) {
    printf("%d\n",  s2.i); // expect 3, got 0
    printf("%d\n",  s2.p == &x); // expect 1, got 0

    printf("%d\n",  s3.i); // expect 9, got 0
    printf("%d\n",  s3.p == &x); // expect 1, got 0
}