Randy said:
(e-mail address removed) wrote
(in article
<
[email protected]>): ....
Hmmm. If it /is/ C code, then it should be portable. If it is
Only if it's strictly conforming C code, which describes a vanishingly
small portion of real C code. Using any standard of conformance less
strict than 'strictly conforming' means that there are platforms it
might not be portable to.
For instance, most of my C code either directly or indirectly calls
many functions that are defined in third-party or system libraris with
names that fall within the namespace reserved for users. Many of those
functions aren't written in strictly conforming C (they are often
written in some other language entirely). That's sufficient to render
my programs non-portable. That's OK because our contract with the
client makes use of those libraries mandatory. Code that's not strictly
conforming for reasons like this one is the norm, not the exception.
....
You do not have to write code that is not portable, although you
may certainly do so. In some cases, it is required. Even then
though, it is possible to use conditional compilation to
generate software that uses platform-specific extensions in part
of the overall source tree yet keeps those exceptions isolated
so that the majority is portable, and adding a new platform to
one of the system-specific modules is minimally painful.
It is possible to use conditional compilation based upon the various
macros defined by the C standard as having implementation-specific
values, to achieve portability. However, if your conditions are
dependent on anything other than those macros, you've probably got a
problem. For instance, the WonderC compiler might specify that it
automatically #defines __WONDERC, and that you should test for this
macro before making use of WonderC extensions. However, there's nothing
in the C standard that prevents the AwfulC compiler from also #defining
__WONDERC, even if it doesn't provide support for WonderC's extensions.
AwfulC could be a perfectly conforming implementation of C, and it
would still be permitted to reject that code, which means that the code
is not strictly conforming. As a practical matter, conditional
compilation based upon such macros is a powerful and effective
technique for making use of implementation-specific features, but
technically it's not guaranteed to work.