Herbert Rosenau wrote On 08/13/06 07:06,:
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:
You are wrong. C is defined by zhe standard. [...]
The Standard's definition of C is incomplete. For example,
the Standard does not define the values of INT_MIN and INT_MAX,
Why should it? It does define well the minimum and maxmimum values a
conforming implementation must hold. True, it does not define that an
int can not be hold a value lower/greater an 16 bit int can hold. It
allows that an int can be significantly wider than 16 bit.
But it defines values who have at least to hold on each conforming
implementation. That is more than any other programming language will
guarantee.
nor whether an `int' bit-field is signed or unsigned,
Right, you may have a need to define signed or unsignded bitfields.
That gives you the guarantee that it works on every mashine you can
find an conforming implementation. There are programming languages
where you not even has the chance to define bitfields at all.
nor what
happens when a negative `int' is right-shifted,
True, because there is hardware existent who will produce something
undefined on negative ints.
nor whether a
`char' value promotes to `int' or to `unsigned int', nor ...
All these matters and more are left to the implementation's
discretion.
That is good so because it increases the chance to write conforming
implementations.
The Standard uses the phrase "implementation-defined"
one hundred sixty-one times, by my count. Not all of these
uses are in normative text, but the number that are normative
is non-negligible. The language is platform-dependent.
No, the language is completely platform independant. For that you have
only to avoid implementation dependant things. And that is easy when
you are able to read and understund the standard. When you are unable
to read or to understund what the standard says then you should never
program a single program anyway.
Don't use yourself platform dependant details in your own code.
[...]
Good advice, to be followed to whatever extent is practical.
Portability (to my way of thinking -- as I said, I'm unaware of
any formal definitions for these terms) is not the same thing
as platform independence, and platform DEpendence need not be
antithetical to it.
When you comes to a point where you has to write a program that has to
run on 16, 62 and 64 bit environments without any change on the source
you'll be happy that the standard defines the language well. I know
that some of my programs I've written with strictly confirmance in
mind is running on platforms I've never seen. I were not able to write
them when the standard were not existent.
The trick was simple. Strongly avoid anything that is not strictly
defined by the standard. Don't use features defined as implementation
defined. It is possible to write even big programs in C (100,000 lines
and more of code, counted without comments and empty lines).
Yes, I've written programs defined and running for a single platform -
and got a hard job every time the version number of the OS was
changed. My customers gets what they payed for,
Truly, some apps are impossible to write 100% portable but there is no
other language that makes it so easy to encaplulate importable
fragments from portable code than C. Don't tell me about Java. Jave
claims to be portable - but in reality it is far fom that in special
when it has to work under the crap from Redmont.
--
Tschau/Bye
Herbert
Visit
http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!