Jeff posted:
I'm taking Intro To Programming Logic. It's fun, plus there's no syntax
to learn! Of course, we still haven't written a program.
Our instructor showed a slide that seemed to illustrate a single C++
(or any HLL) source program being run through compilers on different
"HLL"? What's that?
platforms (Windows, UNIX, Macintosh) to produce a binary with the same
functionality.
That's the aim of "portability". The concept goes as follows:
There's loads of different types of machine with loads of different types of
CPU, and as such they have different CPU instructions and hence different
types of machine code to execute.
The aim of a "portable" language, like C++ for instance, is that you write
C++ code, and this code can be compiled, using a compiler, to produce
different machine code for a wide range of different machines and CPU's.
It's the compilier's job to produce the proper machine code for the
particular platform.
The actual C++ programmer doesn't need to know anything at all about their
"platform" ( ie. the machine, the CPU, the Operating System ) when writing a
portable program.
Just for your information: The following is the minimalistic C++ program. It
is 13 characters long ( 12 plus a new line character).
int main(){}
If this is possible, why don't software vendors do it all the time?
Microsoft could take their Office source code, run it through Sun UNIX
or Macintosh C++ compilers (assuming it's written in C++) and sell the
binary to all computer users. They wouldn't have to create
platform-specific versions.
The actual C++ code itself is portable, yes. But...
In a Win32 program, there's particular functions called, like for instance
"MessageBox".
To the C++ programmer, "MessageBox" works like an everyday function, as if
it resided in their own program. But what happens is that when you run your
Win32 executable, the file "user32.dll" gets loaded (which contains the
function "MessageBox") and then the function is called out of "user32.dll".
What the funciton "MessageBox" does is display a little window that shows
some text and asks you to click OK or Cancel.
So the problem is, if you have code that calls "MessageBox", then it won't
compile for DOS, nor for the Mac.
All of the functions that actually create and display a window that you see
on your screen are Win32 specific.
If you were to write a program for the Mac which displays a window, you'd be
dealing with a totally different set of functions. Maybe you'd have
"TextAndChoiceShower" instead of "MessageBox".
I thought only Java offered this WORM (write once, read many)
capability through the client-installed JVM.
Java is an "interpreted" language. When you compile a Java "application",
you don't get machine code. You get... let's just call it "stuff". When you
run the executable, the Java Virtual Machine then converts this "stuff" into
machine code for use with the current platform.
A broad view:
C++: A compiled language: The C++ code can be compiled for any platform, but
you need a different executable for each platform.
Java: An interpreted language: The "stuff" can run on a few platforms (but
not .01% the amount machines as can C++). The advantage though is that you
only need the one executable for all of your platforms.
Do different CPU chips provide different functionality that you must
write for? Do compilers interpret the same way?
The aim of a portable language...
It doesn't matter if a CPU provides different functionality or different
intructions, I just write my C++ code and get along with it. Producing the
proper machine code is the compiler's problem!
Any insight is appreciated.
Hope that helps.
-JKop