2 ms·
Yes, and with pointer-to-array syntax the bounds checking already works today: https://godbolt.org/z/oc6MTWjYd https://godbolt.org/z/oc6MTWjYd For your syntax
by uecker 3y ago
Yes, and with pointer-to-array syntax the bounds checking already works today:
https://godbolt.org/z/oc6MTWjYd https://godbolt.org/z/oc6MTWjYd
For your syntax we will probably just also add it is an option.
- mananaysiempre 3y agoOne 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.
- uecker 3y agog 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).