3 ms·
Contracts getting proposed but still no slice/span type or even standardization of that new clang feature that makes f(int n, int a[n]) Actually do what it lo
by sirwhinesalot 1y ago
Contracts getting proposed but still no slice/span type or even standardization of that new clang feature that makes
f(int n, int a[n])
Actually do what it looks like it does. Sigh
- veltas 1y agoYou can do f(int n, int (*a)[n]) and it does what it looks like, since C99. https://godbolt.org/z/8dfKMrGqv https://godbolt.org/z/8dfKMrGqv
- sirwhinesalot 1y agoThat's an entirely different thing (VLAs)
- veltas 1y agoThere's no VLA in my example.
- sirwhinesalot 1y agoYour example doesn't do any bounds checks, it just lets you get the sizeof. And the reason the sizeof works is the VLA infrastructure (which is not supported by MSVC so it won't compile the code). What I want is -fbounds-safety from clang.
- navi-desu 1y agoit does do bounds checks if you -fsanitize=bounds, in gcc at least (and msvc is stuck on partial c11 support to this day, so imo, i don't quite think it's a fair target when comparing things to new features anyway)
- miropalmu 1y agoWhat do you mean no slice/span type? https://en.cppreference.com/w/cpp/container/span.html https://en.cppreference.com/w/cpp/container/span.html Or if you want multidimensional span: https://en.cppreference.com/w/cpp/container/mdspan.html https://en.cppreference.com/w/cpp/container/mdspan.html
- sirwhinesalot 1y agoC, not C++. Also span had no bounds checking until the introduction of .at() in C++26, which was a very silly thing to do so late in an age where the white house was asking people to use memory safe languages.
- miropalmu 1y agoOh. Makes sense. My bad.
- TuxSH 1y ago> Also span had no bounds checking While there was no reason not to have .at(), lack of bound checks by default isn't a bad thing, as inlined bound checks have the potential to highly pessimize code (esp. in loops); also standard library hardening is a thing. IMO there's much more value to be had in migrating C code (and pre-C++11 code, too) to C++ (or Rust, depending on one's tastes); RAII - that is to say, the ability to automatically run destructors on scope exit - and in particular shared_ptr/unique_ptr/bespoke intrustive pointers drastically reduce the risks of use-after-free
- sirwhinesalot 1y agoI like how it's handled in Herb's cpp2/cppfront. If the type implements certain methods (like size()), and you turn on bounds checking, then the indexing operations (which are unsafe) are wrapped in i < c.size() ? c[i] : <throw or abort>. This way the indexing operation itself doesn't need to have bounds checks and it's easier for the compiler to optimize out the checks or for an "unchecked" section to be requested by the programmer.
- pjmlp 1y agoStrange are the ways of security in WG14.
- WalterBright 1y agohttps://www.digitalmars.com/articles/C-biggest-mistake.html https://www.digitalmars.com/articles/C-biggest-mistake.html You're welcome!
- uecker 1y agoYou can just define a span type yourself: https://uecker.codeberg.page/2025-07-02.html https://uecker.codeberg.page/2025-07-02.html What new clang feature are you talking about?
- sirwhinesalot 1y ago-fbounds-safety
- uecker 1y agoThis works with new attributes as far as I know.