4 ms·
Is there anything in here for something like a "slice" or dynamically sized array that carries its length along with it?
by thayne 5mo ago
Is there anything in here for something like a "slice" or dynamically sized array that carries its length along with it?
- Panzerschrek 5mo agoJust use compiler option -std=c++20 and use std::span. Don't try reinventing it in C.
- lelanthran 5mo agoIf someone needs more than C provides, why on earth would they choose C++? No rational person is going to want to have to deal with 10x the number of foot guns. Literally anything when moving from C is better than C++.
- Panzerschrek 5mo agoSwitching to C++ is relatively easy in an existing codebase. It's in many cases as simple as renaming a file from .c to .cpp. But for writing something from scratch it's better to use Rust.
- uecker 5mo agoRenaming c. to .cpp may work with ancient c89 code, but not with anything remotely modern. But while the code then is technically C++, it is not better. I still prefer C for new projects to any other language, because I value short compilation time and reduced complexity. For me, this translates in higher productivity and more fun. With modern tooling, also most C issues are detected early.
- Panzerschrek 5mo agoSlightly tweaking C code to allow it working in C++ is still much easier compared to full rewrite in some other language.
- uecker 5mo agoSlightly tweaking might not always be sufficient. Reengineering my numerical code would certainly a bit of effort. But anyhow, I do not think C++ is better. Recently I removed one (!) file with templates (which someone else added) from one of my project because it doubled compilation times (in a project with 750 other files or so). I do no need slow build times, more complexity, and more footguns.
- safercplusplus 5mo ago> It's in many cases as simple as renaming a file from .c to .cpp. That is rather optimistic, but, for example, scpptool has a feature [1] that auto-converts from C to a subset of C that can (hopefully) be compiled with clang++. If the original C source uses C11 extensions, clang++ seems to generally produce warnings rather than compile errors. > But for writing something from scratch it's better to use Rust. scpptool attempts to make C++ a more viable option by enforcing a memory and data race safe subset using a similar safety strategy. [1] https://github.com/duneroadrunner/SaferCPlusPlus-AutoTranslation2/tree/master#auto-conversion-of-c-to-valid-c https://github.com/duneroadrunner/SaferCPlusPlus-AutoTransla...
- cv5005 5mo agostd span is not bounds checked.
- pjmlp 5mo agoIt is when enabling the respective compiler switches for hardned standard library. Even better in C++26.