3 ms·
C doesn't need to look like this. Some of it does, because it comes from the days where function inlining and dead code elimination were aspirational, but your
by JonChesterfield 3y ago
C doesn't need to look like this. Some of it does, because it comes from the days where function inlining and dead code elimination were aspirational, but your C compiler is probably derived from clang or gcc now and totally capable of folding away branches on constant data.
An abstract class is a struct with function pointers in it. Mark the fields const and the instance const and it'll be devirtualised and optimised away. If you miss overloading, `static inline __attribute__((overloadable))` wrappers in a header will bring it back.
Code generators can be better for debugging than built in templates. At the source level they look the same, but if it's behaving weirdly, you can look at the generated C instead of the templated layer.
C code can look rather like modern C++. If you're up for feeding it to a custom preprocessor to implement templates, or especially if you've gone as hardcore as the compiler front end under discussion here, C++ starts to look a lot like a syntactic obfuscation over C.
[it's not quite syntax over C, the languages play divergent games with semantics as well, but picking a different set of syntax abstractions over C to the C++ one is an interesting way to go]
- yau8edq12i 3y agoI can't say I understand the overall point you're trying to make.
- JonChesterfield 3y agoYou're working with embedded C that is a rats nest of macros. It could instead be sanely factored and readable C without the macros if it was written with slightly more trust in the compiler.
- yau8edq12i 3y ago...and you're willing to use nonstandard attributes, code generators, and a custom preprocessor. At this point, why not C++, seriously? And can you show me an example of an existing framework for embedded device that's not the spaghetti code I showed?