News for hackers. Stuff that matters.
Re:Low-Level C Programming – CSE 325 Lecture Videos by pclmulqdq on Saturday March 25, 2023 @11:02PM (#35310356)
I disagree with you here. Off the top of my head, these are the things I like about embedded C++ (and embedded Rust):

* RAII makes modern C++ a lot cleaner for things like holding locks, disabling interrupts, and other stuff that needs to be unwound at function exit, and doesn't need heap allocation. Until C gets 'defer', the cleanest alternative is gotos.

* Operator overloading is pretty nice for code where you have custom data types (like 2-element vectors), which can be very common with DSP systems.

* References give you a non-nullable pointer type.

* Template-based data structures are much nicer than the C alternative: macros.

* std::array is kind of nice, and doesn't have dynamic memory. Also, while std::string is pretty unsafe, std::string_view is very nice!

* For the few dynamic data structures you may want to use, you can write a quick allocator and hook that into every std data structure you want rather than writing your own data structures. The "null allocator" strategy is an option: just return the same pointer to one fixed chunk of memory, and fail if the data structure grows too big. You can also do the "init allocator" strategy: Only allow dynamic allocation during initialization.

Re:Low-Level C Programming – CSE 325 Lecture Videos by mananaysiempre on Sunday March 26, 2023 @03:00PM (#35318153)
Having just written a truly repulsive preprocessor hack, I’m currently in my “maybe C++’s monster of a semantics is not that bad actually” phase (it is that bad though, so that’ll pass). C’s metaprogramming facilities are severely lacking. And yet—

> Until C gets 'defer', the cleanest alternative is gotos.

In an embedded setting, a given project is probably only ever targeting a single compiler, and given that in non-exotic situations it’s a vendor fork of GCC, you should be fine using GCC-specific features. And __attribute__((cleanup)) (essentially a block-scoped defer with cleanup code exiled to a separate function) has been in GCC since (checks docs) version 3.3, from 2003. It would have to be a truly spectacular vendor GCC fork to be missing that feature. (For comparison, the year 2003 also saw the release of Linux kernel 2.6, as in two-six-zero.)