4 ms·
"A cleaned up version of C99 helps avoid low-level bugs. For example, the preprocessor is not supported" NOPE. From my cold, dead hands.
by Nursie 12y ago
"A cleaned up version of C99 helps avoid low-level bugs. For example, the preprocessor is not supported"
NOPE.
From my cold, dead hands.
- IshKebab 12y agoWhy? The preprocessor is a huge hack that is mostly obsolete. 99% of my programs only use `#include` and `#pragma once`.
- metafex 12y agoMacros used right can really help to clean up messy code and/or reduce repeating code to something clearer (e.g. in crypto-code).
- hrjet 12y agoPre-processing macros can reduce repetition, but they are certainly a hack: They are not type-safe. They are not even syntactically safe. A missing brace in one can cause untoward damage down the chain. And getting it right is especially important in crypto-code!
- com2kid 12y ago#ifdef alone #ifdef HW_REVISION_1 #ifdef HW_REVISION_2 etc
- mackwic 12y agoPlaying the devil's advocate, here. When possible, this kind of if_arch/else should be compartmentalized in their own object files or dynamic libraries, and then, linked conditionally to produce an unique binary. You shouldn't clutter your code with ifdef. It makes it hard to think with.
- SixSigma 12y agoThe whole of Plan9 is written like that. If you look here http://plan9.bell-labs.com/sources/plan9/sys/src/9/ http://plan9.bell-labs.com/sources/plan9/sys/src/9/ You can see that port & boot are the portable code. Each architecture can fall back on that less optimised code should it need to. Then each of the directories: bcm, kw, mtx, omap, pc, pcboot, ppc, rb, teg have platform specific c files This greatly eases porting to a new architecture and also means cross compilation is significantly easier. #ifdefs are rare in the source code and other pragmas are few and far between. Conditional compilation is the enemy of readable code.
- sitkack 12y agoMoving and re-moving conditionals is our life. Is there a name for that structure? Polymorphic portability.
- linuxlizard 12y agoWhile I dislike #if/#else/#endif, dynamic libraries rarely exist in embedded systems. Using many small object files is my solution of choice but it pushes the if/else/endif problem into the Makefile instead.
- mackwic 12y agoI personally tend to use yaml files which contains matrices of compatibility between objects, used to generate CMake statements. I know people who use the file header to autodetect the right architecture but I found it too overkill and weird-bug-prone.
- vonmoltke 12y agoThe "when possible" in your statement is a caveat large enough to drive a semi through. Professionally I have only done "big" embedded, but I have for example had a rather lengthy signal processing algorithm where sections needed to be implemented one way for most POWER systems and another way for x86-64 systems. The wrong branch cratered performance[1]. There was no way to separate the code the way you describe without implementing it twice. [1] At the risk of starting a flame war, this situation and those like it have really soured me on the rest of the industry's obsession with "big O" for complexity analysis. I have never found it useful; I always needed to pay attention to the stuff I was supposed to be dropping.