News for hackers. Stuff that matters.
Re:How to Write Portable C Without Complicating Your Build by Keyframe on Friday March 31, 2017 @06:34AM (#14002514)
#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.

Re:How to Write Portable C Without Complicating Your Build by logicchains on Friday March 31, 2017 @08:30AM (#14003008)
That'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.
Re:How to Write Portable C Without Complicating Your Build by ycmbntrthrwaway on Friday March 31, 2017 @09:00AM (#14003226)
Go 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

Re:How to Write Portable C Without Complicating Your Build by marcosdumay on Friday March 31, 2017 @01:13PM (#14005865)
> 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.

Re:How to Write Portable C Without Complicating Your Build by Keyframe on Friday March 31, 2017 @10:36AM (#14004189)
Interesting! I never went in-depth into Go, apart from spending an afternoon with it to have a go at it.
Re:How to Write Portable C Without Complicating Your Build by pjmlp on Friday March 31, 2017 @09:05AM (#14003260)
That has always been my approach as well, much easier than #ifdef spaghetti.