3 ms·
> Most of Rust's "nice security features" are wildly incompatible with existing C/C++ code and inherent language features Such as?
by dependenttypes 6y ago
> Most of Rust's "nice security features" are wildly incompatible with existing C/C++ code and inherent language features
Such as?
- fhars 6y agoLifetimes and the borrow checker.
- dependenttypes 6y agoA linter can do that.
- smolder 6y agoNope.
- dependenttypes 6y agoJust because you lack the ability to imagine something like that it does not mean that it is impossible. Sadly this kind of sentiment seems to be way too common in tech.
- SAI_Peregrinus 6y agoC lacks the information given to the compiler to do this. It can't be added without adding that to the language. So no linter can do this alone, without language changes.
- dependenttypes 6y agoYou can use _Pragma/#pragma, regardless though, you can achieve a lot of what lifetimes can without any annotation.
- SAI_Peregrinus 6y agoPragmas are extensions to C, not part of the C language standard. You can add things to C, but it then ceases to be standard C and becomes GNU C or MS Visual C or early C++ or something else. But not ISO Standard C. And yes, just about anything non-lexical lifetimes can do you can do with static analysis. But the set of things you can do with Rust includes things that need explicit lifetime annotations, which C doesn't have.
- smolder 6y agoIt is impossible given the spec and syntax of those languages, which is why Rust exists, to enable these features...
- pirocks 6y agoThis wouldn't be possible in a practical sense. One could imagine a static analyzer of some kind which infers all lifetimes, though that would likely quickly be unworkably slow on real codebases, since you need to infer programmer intent. Additionally c static analyzers intended to catch all memory errors/UB etc. have existed for decades, and no one uses them, b/c they don't work or have too many false positives. For example did you know that until C++20 allocating an int with malloc was UB in C++? Would you want to work in a language where the linter marked every other line as UB?
- jdub 6y agoIf you think we could get this right in C (48 years old) and C++ (35 years old), don't you think we would have done it by now? :-)
- dependenttypes 6y agoNo, people tend to be quick to create a new language in addition to lacking imagination and thinking that it is impossible to do in C.
- jdub 6y agoToo quick to create a new language?! Rust was started in 2006 and announced in 2010. Its improvements are based on research done before and after C/C++ existed. If you're the only person smart enough to solve the $64B problem so everyone can start writing safe and backwards compatible code in C/C++, please, go right ahead.
- cttet 6y agoyes writing a mini-rust compiler in C is possible and you can write in the mini language. But the problem is: at what cost?
- dependenttypes 6y agoThis has nothing to do with what I am talking about.