←back to thread

228 points Retro_Dev | 1 comments | | HN request time: 0s | source
Show context
blippage ◴[] No.44462083[source]
I tried Zig some time ago to use with microcontrollers. It has a generator for the pins, which was nice. But subsequent versions broke as Zig changed syntax. So I started going down the rabbit-hole (it needed a newer version of llvm, for example) until I eventually decided that the game wasn't worth the candle.

The fact that another breaking change has been introduced confirms my suspicion that Zig is not ready for primetime.

My conclusion is to just use C. For low-level programming it's very hard to improve on C. There is not likely to be any killer feature that some other contender will allow you to write the same code in a fifth of the lines nor make the code any more understandable.

Yes, C may have its quirky behaviour that people gnash their teeth over. But ultimately, it's not that bad.

If you want to use a better C, use C++. C++ is perfectly fine for using with microcontrollers, for example. Now get back to work!

replies(10): >>44462098 #>>44462163 #>>44462194 #>>44462322 #>>44462409 #>>44462430 #>>44462780 #>>44463127 #>>44463517 #>>44464834 #
juliangmp ◴[] No.44462409[source]
Obligatory C is not a low level language: https://queue.acm.org/detail.cfm?id=3212479

I also have to disagree with C++ for micro controllers / bare metal programming. You don't get the standard library so you're missing out on most features that make C++ worthwhile over C. Sure you get namespaces, constexpr and templates but without any standard types you'll have to build a lot on your own just to start out with.

I recently switched to Rust for a bare metal project and while its not perfect I get a lot more "high level" features than with C or C++.

replies(4): >>44462438 #>>44462543 #>>44462692 #>>44464014 #
TuxSH ◴[] No.44462543[source]
> You don't get the standard library

Why is that? Sure, allocating containers and other exception-throwing facilities are a no-go but the stdlib still contains a lot of useful and usable stuff like <type_traits>, <utility>, <source_location>, <bit>, <optional>, <coroutine> [1] and so on

[1] yes they allocate, but operator new can easily be overridden for the promise class and can get the coro function arguments forwarded to it. For example if coro function takes a "Foo &foo", you can have operator new return foo.m_Buffer (and -fno-exceptions gets rid of unwinding code gen)

replies(2): >>44462574 #>>44463081 #
juliangmp ◴[] No.44462574[source]
That's the most frustrating part, a lot of the std library would work on a bare metal system (and would be rather useful), but getting those parts into your project and avoiding the ones that will give you compiler errors in form of esoteric poems is a nightmare.

Vendors at this point seem to give their implementation of some of the std library components, but the one's I've seen were lacking in terms of features.

replies(1): >>44462674 #
1. DanielHB ◴[] No.44462674{3}[source]
This is a problem with WASM as well, use a certain innocent function from the C++ std lib and suddenly your WASM binary grows by 10mb.