473,811 Members | 3,182 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2897
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****@verynam e.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****@verynam e.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****@verynam e.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.progr ammer

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********@hot mail.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****@verynam e.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_Keit h) 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****@verynam e.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
2762
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, a module change its interface or its implementation in a fundamental way (an example: wxPython). This, I think, can be resolved by allowing an user to explicitly say what version of a module it wants (sush as version numbers in Linux shared...
13
9661
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
12
2326
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 typed variables. Thanks, Mark
2
4735
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 Xml key. and refers to the Xml key: <a1:C_XOptions id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/nsassem/SU2000Plus/sekretariat_RM
175
8918
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 changed". This is very much against my instincts. Can anyone offer some solid design guidelines for me? Thanks in advance....
7
2414
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 of the questions, that form is hidden and the next is displayed. Also, as the user answers each question a "count" variable is updated based on their response. I would like the question to show up on the left side and the answer to show up in the...
0
1254
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 test project and found out that the problems is related to generic lists. When I serialize a List<T> with version 1.0.0.0 of the application and deserialize it with version 1.0.0.1 of the application I get an exception stating: Could not load...
15
2069
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 like Symantec's antivirus, NeatReciepts or Franklin Covey's PlanPlus for Windows is any guide, .Net applications are slow and clunky. But, maybe the developers of these apps simply don't know how to write a decent app with .Net.
114
3930
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 to use embedded python in a couple of our new products, given all the great things about python. We were close to using lua but for various reasons we decided to go with python. However, over the last two years, there's been one area of grief...
0
9726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7667
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6887
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5553
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.