Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > how to write os version independent code?

Reply
Thread Tools

how to write os version independent code?

 
 
walter
Guest
Posts: n/a
 
      11-07-2003
I have many computers running Linux. For some reasons,
the versions are not the same. Now, I want to write a C program
to run on them. "Compile once and run everywhere". Is there
anything I have to take care of?

Thanks

 
Reply With Quote
 
 
 
 
walter
Guest
Posts: n/a
 
      11-07-2003
walter:
> I have many computers running Linux. For some reasons,
> the versions are not the same. Now, I want to write a C program
> to run on them. "Compile once and run everywhere". Is there
> anything I have to take care of?
>
> Thanks
>

Some of my PC ares multi-processors, some are not.
The kernel I'm using is 2.4.x.

 
Reply With Quote
 
 
 
 
rihad
Guest
Posts: n/a
 
      11-07-2003
On Fri, 07 Nov 2003 15:08:40 +0800, walter <(E-Mail Removed)> wrote:

> I have many computers running Linux. For some reasons,
>the versions are not the same. Now, I want to write a C program
>to run on them. "Compile once and run everywhere". Is there
>anything I have to take care of?
>


"Compile once and run everywhere"? That's more like Java, I'm afraid. In C it's
rather "Write once and compiler everywhere". In an ideal world, that is...
 
Reply With Quote
 
walter
Guest
Posts: n/a
 
      11-07-2003
rihad:
> On Fri, 07 Nov 2003 15:08:40 +0800, walter <(E-Mail Removed)> wrote:
>
>
>> I have many computers running Linux. For some reasons,
>>the versions are not the same. Now, I want to write a C program
>>to run on them. "Compile once and run everywhere". Is there
>>anything I have to take care of?
>>

>
>
> "Compile once and run everywhere"? That's more like Java, I'm afraid. In C it's
> rather "Write once and compiler everywhere". In an ideal world, that is...


The "everywhere" here is only for my Linux machines.
I don't like java, it's too slow, consumes too much resources.

 
Reply With Quote
 
James Hu
Guest
Posts: n/a
 
      11-07-2003
On 2003-11-07, walter <(E-Mail Removed)> wrote:
> walter:
>> I have many computers running Linux. For some reasons,
>> the versions are not the same. Now, I want to write a C program
>> to run on them. "Compile once and run everywhere". Is there
>> anything I have to take care of?
>>
>> Thanks
>>

> Some of my PC ares multi-processors, some are not.
> The kernel I'm using is 2.4.x.


You can write strictly conforming code. This gives you the best chance
that your programs will do exactly what you intended no matter where
you port your code to, so long the target platform supports the version
of Standard C that you are coding to.

If you require features that are outside of C, your next best bet
is to write code that conforms to POSIX. But discussion POSIX
conformance is beyond the scope of this newsgroup. You best bet
would be to talk to the folks at: comp.unix.programmer

If you require features that are outside of POSIX, then you will
need to dig into the interfaces that are specific to Linux. Your
best bet is to find an appropriate newsgroup under: comp.os.linux*

-- James
 
Reply With Quote
 
EventHelix.com
Guest
Posts: n/a
 
      11-07-2003
If you are just running with the same Kernal, it will actually be hard
to write code that doesn't work the same on different machines.

If you go across multiple CPU architectures you need to be careful
about byte alignment and ordering issues.

Checkout the following article:
http://www.eventhelix.com/RealtimeMa...ndOrdering.htm

Sandeep
--
http://www.EventHelix.com/EventStudio
EventStudio 2.0 - Generate Sequence Diagrams and Use Case Diagrams in PDF
 
Reply With Quote
 
James Hu
Guest
Posts: n/a
 
      11-07-2003
On 2003-11-07, EventHelix.com <(E-Mail Removed)> wrote:
> If you are just running with the same Kernal, it will actually be hard
> to write code that doesn't work the same on different machines.
>
> If you go across multiple CPU architectures you need to be careful
> about byte alignment and ordering issues.
>
> Checkout the following article:
> http://www.eventhelix.com/RealtimeMa...ndOrdering.htm


Byte alignment and byte ordering only become an issue if one writes code
that is dependent upon such things. And if one does so purposefully,
(such as to store data as binary and have it read by a program running
on a different machine), such code relies upon implementation defined
behavior (and can invoke undefined behavior in the program reading
the binary data). Strictly conforming code would not depend upon
implementation defined behavior.

The closest to a Standard C solution to the above scenario would be to
store the data as text. However, it is still implementation defined as
to whether the stored text can be read properly by some other program
running on some other machine. (It depends on EOL discipline, character
set, and perhaps other issues, each issue being off-topic here.)

Since the OP states all his machines are Linux, does Linux on IBM
mainframes use EBCDIC?

-- James
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      11-08-2003
James Hu <(E-Mail Removed)> writes:
> On 2003-11-07, walter <(E-Mail Removed)> wrote:
> > walter:
> >> I have many computers running Linux. For some reasons,
> >> the versions are not the same. Now, I want to write a C program
> >> to run on them. "Compile once and run everywhere". Is there
> >> anything I have to take care of?
> >>
> >> Thanks
> >>

> > Some of my PC ares multi-processors, some are not.
> > The kernel I'm using is 2.4.x.

>
> You can write strictly conforming code. This gives you the best chance
> that your programs will do exactly what you intended no matter where
> you port your code to, so long the target platform supports the version
> of Standard C that you are coding to.


Strict conformance gives you portability of your source code, but the
OP specifically wants portability of the executable. This is
typically difficult or impossible across different processor
architectures (e.g., x86 vs. Alpha), but it's probably feasible if you
limit yourself to x86 systems. It's also well beyond the scope of
this newsgroup.

Try one of the Linux groups (I'm not sure whicn one is best).

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
 
Reply With Quote
 
Malcolm
Guest
Posts: n/a
 
      11-09-2003

"walter" <(E-Mail Removed)> wrote in message
> I have many computers running Linux. For some reasons,
> the versions are not the same. Now, I want to write a C program
> to run on them. "Compile once and run everywhere". Is there
> anything I have to take care of?
>

It's a Linux issue. Some OSes, like MS DOS / Windows, have good backwards
compatibility, others don't.
If your program is pure ANSI C, it will be easy to recompile. However most
real programs need some sort of GUI. Linux should provide
back-compatibility, but again its a Linux issue. Even if a program is
back-compatible, it may be practically unusable - for instance an old
character-mapped program may run, but in many environments it would be
unacceptable to users accustomed to a modern desktop.


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
One Way to Write VCRuntime-Independent Extensions on Windows Lui Core Ruby 0 08-13-2009 04:07 PM
Re: Where to get stand alone Dot Net Framework version 1.1, version2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? MowGreen [MVP] ASP .Net 5 02-09-2008 01:55 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? PA Bear [MS MVP] ASP .Net 0 02-05-2008 03:28 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? V Green ASP .Net 0 02-05-2008 02:45 AM



Advertisments