|
|
|
|
|
by jcoffland
3810 days ago
|
|
As a long time C programmer this is not very convincing. A C program to do the same requires far less voodoo. All you need to do is take the address of the GPIO register then toggle the bit. No name mangling. No error handlers to override. Don't get me wrong I know rust does have some compelling features. It does seem odd to me that so many of what would be compiler options in C are hard coded. |
|
> All you need to do is take the address of the GPIO register then toggle the bit.
Yes, and that is unsafe. Rust makes you put that in an unsafe block, to encourage you to build safe interfaces. This is a good thing.
> No name mangling.
The alternative to name mangling is not having a module system, with all the fun name conflict issues that come with it. Rust made the right decision here.
> No error handlers to override.
C has no concept of a panic handler because what would be panics in C are undefined behavior. Undefined behavior is bad for safety and understandability of the code. Having to declare an error handler is a small price to pay.
> It does seem odd to me that so many of what would be compiler options in C are hard coded.
Because Rust is safe by default. That's one of its most important features. Being more like C in the ways you mention would mean compromising that principle.