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

At least in what concerns C++ there are several ways to try its safety instead of bearing the cost of a full rewrite.

Using standard library types, actually integrating sanitizers into CI, enable bounds checking (even on release builds) and above all avoid C style coding.

Naturally this doesn't work out for third party libraries that one doesn't have control over.

So from a business point of view it boils down how much one is willing to spend re-writing the world vs improving parts of it.



You can write safe code in C++, but it requires you to go way out of your way and exercise constant vigilance, and it's not always obvious when you mess it up. This is the approach we've been trying for 20 years, and it generally hasn't worked well, because people are both flawed and lazy. This is the thing that's fundamentally different about Rust — it provides strong guarantees by default and requires you to specifically call it out when you're doing something potentially unsafe, so to some degree it turns our laziness into a force for good.


> Naturally this doesn't work out for third party libraries that one doesn't have control over.


Also, adress sanitizer but iiuc it's not advised to keep it in production code.


Android ships a subset of it enabled in production.


Interesting, I could not find any links do you have some ?


Sure,

https://source.android.com/devices/tech/debug/asan

https://android-developers.googleblog.com/2019/05/queue-hard...

Also FORTIFY has been being enabled across the codebase and will become default going forward.

https://android-developers.googleblog.com/2019/10/introducin...

Future Android devices on ARM will make use of memory tagging.

https://security.googleblog.com/2019/08/adopting-arm-memory-...


BTW there are garbage collectors for c++


Yep.

C++/CLI, C++/CX, GC pluggable API introduced in C++11, C++ Builder VCL in ARC mode, Unreal C++ managed classes.


Do you know how much c++/cli is automatically compatible with c# code? And how much does it retain compatibility with standard c++?


Everything that obeys to CLS.

https://docs.microsoft.com/en-us/dotnet/standard/language-in...

https://docs.microsoft.com/en-us/cpp/dotnet/managed-types-cp...

Then you can also use regular low level stuff, but in that case you will get mixed mode Assemblies (other forms are now deprecated).

https://docs.microsoft.com/en-us/cpp/dotnet/mixed-native-and...

C++/CLI is basically a set of language extensions, just like clang and gcc have theirs.

Right now it supports up to C++14, if I am not mistaken.

Many don't seem to realise that CLR started as the next evolution of COM, with the required machinery to support VB, C#, J# and C++, alongside any other language that could fit the same kind of semantics.


Thank you, this is very interesting!




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

Search: