Andy wrote:
Hi,
I have read that 'C' is platform-independent and portable. I can'tsee
much a difference between the two terms. Could anyone differentiate the
two? Also is the statement actually true?
Neither term has a precise definition, as far as I know.
By my own notions (others may disagree), I would say that C
is *not* platform-independent: Too many characteristics of the
environment a C programmer confronts are inherited from and
controlled by the underlying platform. The number of bits in
an `int', the way negative integers are represented, the range
and precision of `double', whether floating-point types support
infinities, the syntax and semantics of file name strings -- all
these and more are at the platform's discretion, within broad
limits set by the language Standard. Search the Standard for the
phrase "implementa tion-defined" and you will find that it appears
quite often; each appearance diminishes the language's degree of
platform independence.
On the other hand, the C language is portable in the sense
that it is available on many differing platforms; porting a C
program to a new platform will seldom require that you translate
the code into a different language. C programs can be portable
to varying degrees, depending on how much they rely on the specific
characteristics of a platform. (I find it odd that C programmers
as a class seem apt to resort to non-portable techniques even when
C offers portable techniques that are no trickier; the observation
that "C combines the power of assembly language with the portability
of assembly language" is really more about the way programmers use
C than about C itself.) The ability to write non-portable programs
is both a weakness and a strength of C: a weakness because you cannot
be sure that "an ANSI C program" will port smoothly to a new platform,
and a strength because when you simply *must* stuff a special value
into location 2fff:0800 there's probably a way to do it even if it's
heavily platform-dependent.
A final note: In my view, neither "platform independence" nor
"portabilit y" are Boolean attributes. Nor are they scalar; they
seem to me to be multi-dimensional. They are not even objective:
portability is always assessed in terms of the likely universe of
desirable target platforms, and different programmers anticipate
different audiences.
--
Eric Sosman
es*****@acm-dot-org.invalid