6 ms·
A dead lingua franca, Like Latin. Could happen, but I suspect embedded programmers will stick with C forever.
by MaxBarraclough 8y ago
A dead lingua franca, Like Latin. Could happen, but I suspect embedded programmers will stick with C forever.
- kccqzy 8y agoThis is one reason I don't really like embedded programming. There seems to be generally a fear of newer systems languages like Rust and a fear of newer features in C++. An embedded programmer told me he doesn't use the C++ STL because he doesn't want functions allocating stuff on his back. Doesn't seem very convincing as you can always redefine the global operator new.
- kstenerud 8y agoIt's not a problem of how things are allocated, but rather when. In an embedded environment, you need to be very aware of what is being used at any given time and how, and complex templates like in STL have a tendency to allocate and deallocate in ways that can be difficult to follow, or might have a worst case memory footprint that blows through your RAM.
- foundry27 8y agoNot disagreeing with your point about STL classes having a tendency to make egregious allocations (heck, a lot of them are fundamentally designed around using allocators for pretty much everything), but the fact that they’re often complicated templates is totally orthogonal to that, and I think it’s disingenuous to say that there’s a causal relationship between the two. If anything, templating encourages statically-verifiable, compiler-enforced code invariants and outputs, which can be pretty darn nice for embedded.
- rcxdude 8y agoThere is a fair amount of interest in Rust from embedded programmers, though at the moment you can only really use it for ARM cores (which are probably among the most common embedded cores but there are a huge number of alternatives). There is a dedicated working group within the rust community for embedded which is pushing towards having a good user experience for those wanting to use Rust in such an environment. But even within embedded rust you won't find much appetite for dynamic memory allocation, and a fair amount of the work has been stabilizing the mechanisms by which you can build rust code which does not use its standard library ('no_std'). This has nothing to do with the fear of the new and lots to do with predictability of code. Using a single heap for all allocations is not at all ideal in an embedded context: your allocations become much harder to predict (both in terms of failure and in terms of time taken), errors become harder to recover from, and it becomes harder to reason about the amount of memory your system will use (especially in edge cases). For embedded work you will generally try very hard to allocate everything statically, and use some kind of pool allocation if you cannot (and often you combine the allocation and whatever datastructure you are placing the objects in).
- josephg 8y ago> Using a single heap for all allocations is not at all ideal in an embedded context The same is true in game development. Using a per-frame arena allocator for short lived objects can make a big difference to performance. And Rust’s lifetime rules can be used to make this sort of thing completely safe. It’s a shame that rust std completely relies on the hidden global allocator instead of accepting an allocator as a parameter. It means that while you can write your arena allocator, you can’t use it with any of the built in Box/Vec/HashSet/etc types. I actually really like Zig’s answer here of just passing in an allocator as an argument in all data structures. I’d love to see that in rust!
- steveklabnik 8y agoWe didn’t have an allocator API, or we would have liked to. Global allocators have finally stabilized. Working on it!
- rkangel 8y ago> There seems to be generally a fear of newer systems languages like Rust It's not fear of newer languages (most of the time). I would love to use Rust for embedded in a professional environment but it loses out quickly based on supported platforms. As leader of an embedded development team, I can't choose a language that will limit the processor parts we can use when we get closer to manufacturing and cost reduction. At volume, many millions spent on software development is dwarfed by cost savings from swapping in the right part.
- oblio 8y agoI've always been curious about this, could you give more details? It would be interesting to know what a 8-bit chip costs vs a 32-bit one, for example.
- rkangel 8y ago8 Bit chips tend be anywhere from 1 cent to $3 in volume. 32 bit chips are usually be from $1 to $20. It doesn't tend to be that extreme a part swap - if you're doing signal processing and UI then you're probably always going to use a 32 bit part. If you're just doing some basic logic with a couple of digital inputs then you're probably always going to use an 8 bit part. You might move 32 bit ARM to 16 bit MSP430 to hit a power budget or similar. Leaving aside processor architecture, the factors that affect cost from most to least (approx) are: Flash size, number of peripherals/features, clock speed, ram size. Basically, sometimes another manufacturer will have a part that meets your feature requirements much cheaper, and then you port the code. The rest of the time, you're just squeezing program space, memory usage and processor usage to reduce the required specs.
- shaklee3 8y agoFrom what I recall, SpaceX doesn't allow any external libraries in their embedded rocket code.
- pjmlp 8y agoYeah, most of them are still on C89, even if the compilers do C11.
- MaxBarraclough 8y agoReal C programmers use C89, huh.