Is C portable from PC to UNIX

E

emmitsuks

Can I compile C source in an PC editor like Miracle, build it, and then
take that .exe over to Unix and run it there?


Is there a preferred group for beginners such as myself to join?
 
J

John Bode

emmitsuks said:
Can I compile C source in an PC editor like Miracle, build it, and then
take that .exe over to Unix and run it there?

If you use a cross-compiler and build for the target machine, then yes.
However, an executable built *for* Windows on x86 will not run
natively on Unix, especially if that Unix is running on different
hardware (PPC, MIPS, PA-RISC, Sparc, etc.).
Is there a preferred group for beginners such as myself to join?

If your questions are about the C *language*, then this is as good a
group as any (just have some asbestos underwear handy).
 
W

Walter Roberson

If you use a cross-compiler and build for the target machine, then yes.
However, an executable built *for* Windows on x86 will not run
natively on Unix, especially if that Unix is running on different
hardware (PPC, MIPS, PA-RISC, Sparc, etc.).

<OT>

Though if you happen to want to run the Windows x86 code on an x86
based machine running any of several Unices or Unix-like systems
such as Linux, then there are free and commercial programs that
apparently do fairly good jobs of running the code. For non-x86
systems there are virtual machines or emulators available that
can run the x86 Windows code... possibly slowly.

One option to consider is to do the development on Windows but using
a Unix emulation library such as MingW or AT&T's UWIN; once that code
was working, taking the -source- to a Unix system and rebuilding would
usually be within a reasonable amount of work. But there are quite
a few flavour of Unix, so sometimes it does turn out to be a lot of
work, depending exactly what you are doing.

You can reduce the amount of work required to "port" a program
from Windows to Unix, by restricting yourself to the facilities provided
by the C language, and avoiding graphics, GUIs, networking, or
anything that needs to know about the "inside" of how the system
does its work. This newsgroup, comp.lang.c, often has discussions
about what is or is not part of the C language, so it is a good place
to visit if you want to write programs that are intended to be as
portable as practical.
 
E

emmitsuks

thanks, I guess I should start trying to familiarize myself with an
editor on Unix like nano or vi instead of miracle or visual c
 
P

Peter Nilsson

emmitsuks said:
Can I compile C source in an PC editor like Miracle,

Compilers may come with editors, but an editor is not a compiler.
build it, and then take that .exe over to Unix and run it there?

Generally no, not unless you're running a PC emulator on the Unix box.
Is there a preferred group for beginners such as myself to join?

You could try alt.comp.lang.learn.c-c++, but be sure to read the FAQ
before posting questions. Also realise that NO forum is good for
teaching you a language from the basics. Forums can help clarify
specific doubts on specific issues, but there are much better
structured tutorials that can help you learn C as a whole.
 
M

Michael Rasmussen

You can reduce the amount of work required to "port" a program from
Windows to Unix, by restricting yourself to the facilities provided by the
C language, and avoiding graphics, GUIs, networking, or anything that
needs to know about the "inside" of how the system does its work. This
newsgroup, comp.lang.c, often has discussions about what is or is not part
of the C language, so it is a good place to visit if you want to write
programs that are intended to be as portable as practical.
If GUI is important the use a portable graphics library like qt, gtk or
wxwidgets.
 
C

CBFalconer

emmitsuks said:
thanks, I guess I should start trying to familiarize myself with
an editor on Unix like nano or vi instead of miracle or visual c

VIM and EMACS have been ported everywhere. If you settle on one of
those you will not need to change any habits when moving between
systems.

--
"The power of the Executive to cast a man into prison without
formulating any charge known to the law, and particularly to
deny him the judgement of his peers, is in the highest degree
odious and is the foundation of all totalitarian government
whether Nazi or Communist." -- W. Churchill, Nov 21, 1943
 
A

August Karlstrom

CBFalconer said:
VIM and EMACS have been ported everywhere. If you settle on one of
those you will not need to change any habits when moving between
systems.
....or between programming languages.


August
 
W

Walter Roberson

VIM and EMACS have been ported everywhere. If you settle on one of
those you will not need to change any habits when moving between
systems.

Dah. The Mars lander was lost because in the heat of the moment,
someone confused META-X and CONTROL-X before "deploy-parachute".
 
N

Nelu

emmitsuks said:
thanks, I guess I should start trying to familiarize myself with an
editor on Unix like nano or vi instead of miracle or visual c
Please red this: http://cfaj.freeshell.org/google/
If you want to spend time on this group you should learn some
things about how to write things on the group.

Now, I think it's good to learn how a program is put together. IDEs
like Visual C++, KDevelop and others are hiding things from you,
things that, I think, you should know about. I wouldn't use nano
but I would use a programmer's editor like vi or emacs. Given the
fact that these are source files, you can use whatever text editor you
want. Just remember, word is not a text editor :).

If you are interested in portable applications then you might want
to know that compiled software written in C is not usually portable
across platforms. Code written specifically for Windows (using
GUI, or Windows API, in general) is even less portable.
If you want something that let's you have portable source across
quite a lot of operating systems and use C then you should take
a look at gtk+. If you are just a C beginner I would sugest to forget
all about graphics and stuff like that and learn to master C.
 
D

Dave Thompson

One option to consider is to do the development on Windows but using
a Unix emulation library such as MingW or AT&T's UWIN; once that code
was working, taking the -source- to a Unix system and rebuilding would
usually be within a reasonable amount of work. <snip>

Cygwin. MingW is GCC on the M$ (runtime) library plus only the patches
needed for conformance as C but not (full) Unix.

Though, if you limit yourself to Standard C, you can port from either
MSVC (carefully ignoring all the tempting extensions) or mingw to Unix
or vice versa. You can even add easily <OFFTOPIC> the portion of
Winsock that is almost nearly compatible with Berkeley sockets </>.

- David.Thompson1 at worldnet.att.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top