4 ms·
#if defined(PLATFORM) I would recommend against that as well. I have a directory structure where there's a module/hello.c (stub or generic, platform independe
by Keyframe 10y ago
#if defined(PLATFORM)
I would recommend against that as well.
I have a directory structure where there's a module/hello.c (stub or generic, platform independent code) and then there's module/platform/hello.c which my Makefile selects over the generic one based on the platform. Primary issue is that there's some code duplication, and it's hard to keep .h files general across platforms all the time (not possible all the time), but in general it does make life a lot easier - especially if platform number grows over time or certain are removed.
- logicchains 10y agoThat's quite similar to how Go does it (Go would have something like hello_platform.c), which in my opinion works quite well. I actually find it to be one of the nicest things about Go, compared even to Haskell, which for some bizarre reason uses the C preprocessor (!!) to pepper code with #ifdefs.
- ycmbntrthrwaway 10y agoGo took this idea from Plan 9. In fact, Go shares a lot with Plan 9 C compiler structure. Related: http://doc.cat-v.org/henry_spencer/ifdef_considered_harmful http://doc.cat-v.org/henry_spencer/ifdef_considered_harmful
- Keyframe 10y agoInteresting! I never went in-depth into Go, apart from spending an afternoon with it to have a go at it.
- marcosdumay 10y ago> for some bizarre reason uses the C preprocessor (!!) to pepper code with #ifdefs. I always thought that was funny. You are using the most powerful (of the widely used) language available for transforming text, but must fall back to the C preprocessor.
- pjmlp 10y agoThat has always been my approach as well, much easier than #ifdef spaghetti.