Most of my work is focused on embedded targets, many of which have oddball inconsistencies in either the stdlib or os available. So, if your like me, you’ve had to experience the pain of wading through source that’s become a mishmash of #ifdefs in the name of portability. If another platform was added, yet another set of #ifdef’s would need to be added to add support, and woe to the develop who had to maintain the codebase.
A straightforward example would be part of the openssl codebase:
In thlock.c, You basically have the following configuration:
The above code covers only 4 operating systems in somewhat of a simplistic way, with little margin for wide variation between platforms. With a little imagination, one can also see where additional branches would eCos, uCos, bare-metal (no-os). In particular, the bare metal or embedded os implementation would pull in quite a bit more code, further muddying the waters.
I think there’s a better way to manage this via the build process. The #ifdefs can be replaced by a clean platform-based folder structure.
, another ifdefthe original project are added without Managing cross platform code falls into a couple different camps. The default mode is to utilize the #ifdef PLATFORM_FOO idiom to manage differences between platforms.
Platform dependency handling can fall into two camps.
The problem – ifdef discussion
Source tree structure
Marginal to good examples
http://svn.apache.org/repos/asf/httpd/httpd/trunk/ – makes an attempt to factor out os specific code to the os library/