Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Platform Independence

Reply
Thread Tools

Platform Independence

 
 
Andy
Guest
Posts: n/a
 
      08-12-2006
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?
Thanks
Andy

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      08-12-2006
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?


I don't think you should differentiate between them, they are
complimentary. You can get a C compiler for just about any processor
and standard conforming code will compile and run on them.

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      08-12-2006
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 "implementation-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
"portability" 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
http://www.velocityreviews.com/forums/(E-Mail Removed)lid
 
Reply With Quote
 
Thad Smith
Guest
Posts: n/a
 
      08-12-2006
Andy wrote:

> I have read that 'C' is platform-independent and portable.


Standard C /can/ be used in a platform-independent way, but it takes
care and effort to achieve this, since there are many
implementation-defined and unspecified aspects of C. Two's complement
arithmetic and integer bit length which is a power of two are examples
of features that are common to most platforms, but not guaranteed in the
Standard.

To achieve the most portability, use only the features that Standard C
supports. Unfortunately, there are often implementation-dependent
things that the programmer wants to do, so he must use platform-specific
extensions or libraries. Common examples are graphics, multi-threading,
and menu systems. There are some multiple-platform libraries that make
portability easier.

The best approach is usually to use Standard C as much as feasible and
collect non-standard usage to a few functions and modules. This makes
porting easier.
--
Thad
 
Reply With Quote
 
napi
Guest
Posts: n/a
 
      08-13-2006
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?


Hi:

You can try AMPC at http://www.axiomsol.com
It is a C compiler that generate Java class files for the purpose of
achieveing platform independence via the JVM.

Regards.

Napi

 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      08-13-2006
napi wrote:
> 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?

>
>
> Hi:
>
> You can try AMPC at http://www.axiomsol.com
> It is a C compiler that generate Java class files for the purpose of
> achieveing platform independence via the JVM.
>

On an 8 bit micro?

--
Ian Collins.
 
Reply With Quote
 
Flash Gordon
Guest
Posts: n/a
 
      08-13-2006
Ian Collins wrote:
> napi wrote:
>> 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?

>>
>> Hi:
>>
>> You can try AMPC at http://we.are.spamming/
>> It is a C compiler that generate Java class files for the purpose of
>> achieveing platform independence via the JVM.
>>

> On an 8 bit micro?


Nope. I doubt it would run on my (or my customers) SCO boxes not a
number of others when I run standard C programs built with the standard
port of gcc to those platforms.

Since the OP was not asking for such tools but asking for definitions of
terms I would say that AMPC was very close to being spammed. It also
still does not support C89 (it doesn't support C99 either).
--
Flash Gordon
Still sigless on this computer.
 
Reply With Quote
 
Herbert Rosenau
Guest
Posts: n/a
 
      08-13-2006
On Sat, 12 Aug 2006 20:16:12 UTC, Eric Sosman
<(E-Mail Removed)> wrote:

> 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. Write your program in C
as the standard it defines and you ends up in a program that is
absolutely platform independent. I've proven that multiple times.
Write once, compile on each environment and run.

Too many characteristics of the
> environment a C programmer confronts are inherited from and
> controlled by the underlying platform.


That is why C exists. It is the job of the C environment to hide
platform dependant things from you.

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 "implementation-defined" and you will find that it appears
> quite often; each appearance diminishes the language's degree of
> platform independence.


Don't use yourself platform dependant details in your own code. The
standard guaratees a lot of things. Live inside the guarantees and you
would not change a single bit in your code to get it compiled and
running on highly different platforms - even on such you've never
heard before.


> 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,


Not true. Write a conforming program any you can pot it by only
compile for the 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.


Yes, you will write complete incompatible program when your program is
based on functionality only defined on a specific platform. But on the
other hand you can even then write lots of the fuctionality strictly
portable by encapsulationg incomplatible functions and write only the
nonportable sections separately.

I've done that in a team of about 50 peoples for 10 completely
incompatible systems by rewriting only 25% of the total amount of 30
million lines (comments stripped) of code, having the other 75%
strictly conforming.

> A final note: In my view, neither "platform independence" nor
> "portability" 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.
>

No, you can only been portable or not. You can only been platform
independant or not.
Your progam in whole can be both in same time.

--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
 
Reply With Quote
 
Ancient_Hacker
Guest
Posts: n/a
 
      08-13-2006

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?
> Thanks
> Andy


Er, Um, let's put it this way:
"Portability" isnt a yes/no issue. Let's try rating languanges on a
scale from zero to 100%, portability-wise.

Now this is a bit unfair-- many languages were developed before the
concept of "portability" was considered an important language
attribute. But let's plow ahead.

If we define portability as "The average programmer, writing say 1000
lines of code, taking no special emphasis on writing portable code,
will end up with a program that will run on xx% of the machines out
there"

let's take a wild stab at this, you may have other opinions, but this
is my guess:

Perl, COBOL, SNOBOL, Lisp: 85 to 95%

Pascal, Fortran 95, php, Java, SQL, , APL(100 lines): 70 to 84%

C, C++: 30 to 69%

Javascript, csh, sh, BASIC: 1 to 29%

Your opinion may vary.

----
(Explanation)
Some languages were intended to be portable, others have been
rigorously standardized into a semblance of portability, others are
portable because there exist "portable" implementations, others are
soooo loosely designed, or so dependent on system features that the
average program isnt very portable, or it's hard to remember all the
restrictions for writing portable programs.

So to answer your question, IMHO, C falls into the next to the bottom
category for portability. Mildly modify that by the fact that with
macros and #ifdefs and ./configure scripts you can coerce a C program
into a reasonable exterior semblance of portability.

 
Reply With Quote
 
Stephen Sprunk
Guest
Posts: n/a
 
      08-13-2006
"Herbert Rosenau" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)-ROSENAU.DE...
> On Sat, 12 Aug 2006 20:16:12 UTC, Eric Sosman
> <(E-Mail Removed)> wrote:
>> 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.

>
> Yes, you will write complete incompatible program when your program is
> based on functionality only defined on a specific platform. But on the
> other hand you can even then write lots of the fuctionality strictly
> portable by encapsulationg incomplatible functions and write only the
> nonportable sections separately.
>
> I've done that in a team of about 50 peoples for 10 completely
> incompatible systems by rewriting only 25% of the total amount of 30
> million lines (comments stripped) of code, having the other 75%
> strictly conforming.


That seems to be the typical model. The amount of non-portable code you
need in your abstraction layer will depend on your exact needs and whether
or not you're running on top of some sort of OS or having to write your own
drivers, scheduler, etc., but every "portable" program I've seen follows the
same general idea: there's an abstraction layer which has to be rewritten
for each new target, but the bulk of the program logic is portable.

> No, you can only been portable or not. You can only been platform
> independant or not.
> Your progam in whole can be both in same time.


Not in whole, no, but the beauty of C is that you can have individual
modules that are one or the other _written in the same language_ within the
same program.

S

--
Stephen Sprunk "God does not play dice." --Albert Einstein
CCIE #3723 "God is an inveterate gambler, and He throws the
K5SSS dice at every possible opportunity." --Stephen Hawking



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl# then Language# - Platform independence sln@netherlands.com Perl Misc 2 12-15-2008 09:47 PM
Connecting Win98 platform to WinXP Pro platform dancesportboston Wireless Networking 1 09-02-2006 10:36 PM
does java program run on 64-bit platform as fast as on 32-bit platform jcc Java 15 05-12-2006 08:52 AM
New Windows platform and 64 bit platform =?Utf-8?B?T21hciBLaGFu?= Windows 64bit 12 11-30-2005 11:05 PM
How can I convert the C6.0 program of OS/2 platform TO a program in windows2000/xp platform? Coca C Programming 15 01-14-2004 04:44 PM



Advertisments