473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

how to write os version independent code?

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

Nov 13 '05 #1
8 2878
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.

Nov 13 '05 #2
On Fri, 07 Nov 2003 15:08:40 +0800, walter <gw****@veryname.com> 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...
Nov 13 '05 #3
rihad:
On Fri, 07 Nov 2003 15:08:40 +0800, walter <gw****@veryname.com> 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.

Nov 13 '05 #4
On 2003-11-07, walter <gw****@veryname.com> 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
Nov 13 '05 #5
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
Nov 13 '05 #6
On 2003-11-07, EventHelix.com <ev********@hotmail.com> 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
Nov 13 '05 #7
James Hu <jx*@despammed.com> writes:
On 2003-11-07, walter <gw****@veryname.com> 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) ks*@cts.com <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 13 '05 #8

"walter" <gw****@veryname.com> 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.
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Manlio Perillo | last post by:
Hi. I'm a new user of Python but I have noted a little problem. Python is a very good language but it is evolving, in particular its library is evolving. This can be a problem when, ad example,...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
12
by: Simula | last post by:
Hello All, Does anyone have any knowledge of when version 4 will be released? I think that version 3 was finalized in 1999 and it would be really nice to have the class keyword and statically...
2
by: Wiktor Zychla | last post by:
After signing all my assemblies with strong keys, I've found that the application refuses to deserialize any SOAP serialized data. The message says: Parse error, no assembly associated with the...
175
by: Ken Brady | last post by:
I'm on a team building some class libraries to be used by many other projects. Some members of our team insist that "All public methods should be virtual" just in case "anything needs to be...
7
by: Andrea | last post by:
Hi there - I'm hoping someone can help me; I've been struggling with this for a few days! :-) I have a webpage that is comprised of many forms containing questions. As the user answers one...
0
by: Michael | last post by:
I have a problem with serialization in my project. Serialization is working fine so far but when I increase the version of the application in the AssemblyInfo.cs I get an exception. So I created a...
15
by: jim | last post by:
Maybe I'm missing something, but it doesn't look like Microsoft writes a lot of apps in .Net (although they certainly push it for others). What does MS write using pure .Net? If applications...
114
by: Andy | last post by:
Dear Python dev community, I'm CTO at a small software company that makes music visualization software (you can check us out at www.soundspectrum.com). About two years ago we went with decision...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.