Hacker Timesnew | past | comments | ask | show | jobs | submitlogin

One potential difference is variance: AFAIU, if

  void f(char (*pa)[7]);
  void g(int x, char (*pa)[x]);
  void h(int x, char p[static x]);
  char a[10];
then f(&a) is a constraint violation, and I believe g(7,&a) might actually be UB, whereas h(7,a) is fine. On the other hand, in the latter case

  void h(int x, char p[static x]) { p = (char *)&x; }
is legal, so extending that with bounds checks is also not without its problems.


g is UB which is why one can use it easily for checking. h is fine because a is larger than 7. If it were smaller the call could be diagnosed. If you overwrite the pointer inside the function, then the bounds will be lost. (which is different to pa = ... where the bounds still need to match).




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: