News for hackers. Stuff that matters.
Re:Cello – High Level C by girvo on Saturday March 05, 2022 @04:07AM (#30565825)
If you have to use C to extend an existing system, or hook into one, or leverage C code and so on, I found Nim to be brilliant. Because it is C once compiled.

I’m using it right now at work to build our firmware for our custom embedded board. It’s been brilliant: ESP-IDF is all C (mostly, some C++ but it all has C interfaces too) and wrapping, extending, calling and integrating into those has been a breeze.

Re:Cello – High Level C by monetus on Saturday March 05, 2022 @10:46AM (#30568474)
Nim wrapped around a good library can feel liberating. I feel like using it and FFIs is too uncommon.
Re:Cello – High Level C by girvo on Monday March 07, 2022 @01:39AM (#30584830)
I always get a bit sad when a nice library I come across in the wild is C++, as FFI to C++ is so much more... fiddly, in all languages, compared to a C library. The latter is a breeze.

In fact, today, I needed to be able to call the `esp_pthreads.h` functions (which describe some ESP32-specific extensions to it's pthread layer) and it took me, no joke, 5 minutes to wrap.

Pass the header through c2nim, add `{.importc, header: "esp_pthreads.h".}` pragmas to the proc definition, and done. Now I can call them without issue. Its liberating for sure!

That said, you can even wrap C++ if need be, though it's less elegant at times.