Greg Comeau wrote:
Quote:
In article <1161464042.327302.203290@i42g2000cwa.googlegroups .com>,
Kaz Kylheku <kkylheku@gmail.comwrote:
Quote:
#if INCLUDE_MY_LIB_SUPPORT
#endif
[ snip ]
Quote:
Quote:
If you forget to define it, then the #if is ill-formed, having no
expression.
>
Fairly certain in the case above it is well formed as any ids
not replaced become replaced by a 0 token.
Ah crap, right.
Then, to defeat all this defaulting, you can to impose an enumeration.
For instance, the rule that two symbols must be defined:
#if defined INCLUDE_MY_SUPPORT
...
#elif !defined NO_INCLUDE_MY_SUPPORT
#error must explicitly request no support
#endif
The obvious alternative way to solve the original problem is to create
an API which is always defined, and always called. On the subset of the
platforms that have the special library, the API calls the library. On
the platforms where it doesn't, the API is just stubs that do the right
kind of nothing for each function.
// In the header file
#if .. test for all the platforms where library is supported ...
// #include or otherwise define the library API
int library_function();
#else
// define dummy version of the API which does nothing, using inline
functions
inline int library_function() { return 0; }
// or, using macros:
#define library_function() ((int) 0)
#endif
And so now there is no special dance to repeat in the sources, where
you simply call the function:
library_function(); // might do nothing if not supported
This also takes care of the forgotten header include.