| ▲ | pornel a day ago | |
Depends how you define "can", because you can invent your own conventions not checked by the compiler, or even make a compile-to-C language. But more directly, C barely lets you define non-NULL pointers. It doesn't have pointers that guarantee the data behind them is initialized, it doesn't have never-leaves-this-thread data types. Const merely guarantees that you can't (strongly shouldn't) mutate data, not that it definitely won't be mutated by any thread. | ||
| ▲ | uecker 15 hours ago | parent [-] | |
Most of this can be done just fine in practice. NULL safety is not so much an issue as people claim as trapping is safe on most implementations and then similar to a panic in other languages. If you create data types via constructors you can then make sure those are initialized. Yes, this is a convention but easy to check. The const issue is not a problem IMHO. If you violate type safety yourself then this comparable to using escape hatches in other languages. Only the never-leave-this-thread point is something where Rust truly has an advantage, but one can have abstract data types that are thread-safe in C. This is why I think a book is missing, people think C is much worse than it is because they do not understand what can be achieved. | ||