5 ms·
Let's not forget microcontrollers, the moment one wants to write something more universal (different MCU support) using ifdefs is basically unavoidable.
by Avamander 8y ago
Let's not forget microcontrollers, the moment one wants to write something more universal (different MCU support) using ifdefs is basically unavoidable.
- pjmlp 8y agoNot when using one translation unit per MCU and letting the Makefile pick the right one. Back on my C days, I was able to write portable code between Windows NT, Windows 2000, Red-Hat Linux, Debian Linux, Aix, HP-UX, Solaris where the #ifdef were only used as include guards, regarding my own code.
- monocasa 8y agoSeconded. And it's only gotten better, as uc code is about the best case for LTO being both small and all in one final image. Now there's not even the specious argument about "artificial" compilation unit boundaries hurting performance terribly.
- namibj 8y agoAlso, you'd be surprised how heavy software can get without outgrowing single-unit LTO, as long as you don't try to pull in all of Qt/GTK or similar bloat in. (I don't see those as a bad choice, but they are too heavywight for this style of LTO to work well.)
- Avamander 8y ago> Not when using one translation unit per MCU and letting the Makefile pick the right one. Could you please link any examples of that I could examine myself? Also, makefiles aren't really an option with platforms like Arduino, the IDE does not really support them.
- namibj 8y agoErr, you can use the Arduino ecosystem with gnu make.... look for it, there is documentation, which does have ease of use to wish for and requires installation that drives me towards believing in chroot.
- Avamander 8y agoSure I can, but it's ugly and cumbersome and doesn't work when you try to provide a library that could be used with the IDE.
- pjmlp 8y agoAs you can see from my OS list, those days were a while back. Basically I adopted some ideas from Pascal/Modula world, plus some tips from somewhere/someone during my university days. Basically you consider a translation unit as C's vision of a module, and use Abstract Data Type types for the data structures. The header contains the common code, and only on performance critical code are used macros instead of functions (validated with profiler that is worthwhile doing so). Then you have module.c for the common code, followed by module_os.c for each platform. Sorry for not providing Makefile rules, it has been a while.
- stevekemp 8y agoPeople have written Makefiles for arduino-projects, for example this project: https://github.com/sudar/Arduino-Makefile https://github.com/sudar/Arduino-Makefile To be honest the simpler way is to do it "by hand", if you enable the appropriate options in your arduino IDE you can see the actual compilation-commands which are executed. Copy and paste them to a Makefile.. I'm very familiar with make, etc, but still use the IDE for my Arduino projects (simple as they might be). I just use Emacs as an external editor.