fuhsnn / slimcc

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

Address-of-array (`&`operator) behavior #14

Closed fuhsnn closed 11 months ago

fuhsnn commented 11 months ago

This should be valid:

#include <stdio.h>

int main(void) {
  char arr[3] = {11, 22, 33};
  int i;
  i = (&arr)[0][2], printf("%d\n", i); // 33
  i = (*&arr)[1], printf("%d\n", i); // 22
  i = (**&arr), printf("%d\n", i); // 11
}

and for pointer arithmetic, incorrect offset:

  i = (long)(&arr + 3) - (long)(&arr); // expect 9, got 3