Re:Raspberry Pi Bare Metal Programming with Rust
by mpweiher on Sunday January 17, 2016 @04:27AM
(#10918934)
> Not every engineering decision is a tradeoff.
Scratch the "not". For example, if I have a small-enough code-base, a module-system, is not worth it, unless it has zero cost. Or if the module system doesn't fit my needs, it will often be easier to create what I need if I don't have to work around what is there. Same with error handlers.
Every engineering decision is a tradeoff, though you may be in a space where the tradeoffs obviously point in one direction.
Re:Raspberry Pi Bare Metal Programming with Rust
by pcwalton on Sunday January 17, 2016 @04:33AM
(#10918947)
A module system is always worth it because every program needs to use library functions. Even if you think you don't, LLVM will generate calls to library functions for ordinary code; for example, if you move structures around on the stack, LLVM might just decide to call memcpy(), even if you didn't ever import string.h. (Checking your code after the fact to verify there are no library calls doesn't get around this because a new version of the compiler might add a library call where there wasn't one before.) Now you want some mechanism to isolate your code's names from the library's names. That's a module system.
Re:Raspberry Pi Bare Metal Programming with Rust
by nitrogen on Sunday January 17, 2016 @06:00AM
(#10919105)
Does bare metal Rust also use memcpy() or other library functions? If so, how are those linked into the final binary?
Re:Raspberry Pi Bare Metal Programming with Rust
by steveklabnik on Sunday January 17, 2016 @08:51AM
(#10919442)
Yes, LLVM will assume three or four functions exist regardless. The rlibc crate provides a Rust implementation of them, so you just add it and you're done. https://github.com/alexcrichton/rlibc
Undefined behavior and the lack of namespacing don't fall into this category, though. C would be a better language all around if it required that null pointer dereference trap to an error handler (at least on hardware with an MMU or MPU). It would also be a better language if it had a module system.
Not every engineering decision is a tradeoff. Sometimes certain decisions are just better all around. I think that modules and error handlers fall into this category.