Newbie Question

J

Jeff

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 platforms
(Windows, UNIX, Macintosh) to produce a binary with the same functionality.

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.

I thought only Java offered this WORM (write once, read many) capability
through the client-installed JVM.

Do different CPU chips provide different functionality that you must write
for? Do compilers interpret the same way?

Any insight is appreciated.
 
V

Victor Bazarov

Jeff said:
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 platforms
(Windows, UNIX, Macintosh) to produce a binary with the same functionality.

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.

I thought only Java offered this WORM (write once, read many) capability
through the client-installed JVM.

Do different CPU chips provide different functionality that you must write
for? Do compilers interpret the same way?

Are you for real or is this another Java-promoting troll? Talk to your
course instructor, he must be able to help you answer your questions.

V
 
M

Malte Starostik

Jeff said:
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 platforms
(Windows, UNIX, Macintosh) to produce a binary with the same functionality.

That is called a portable program. The definitions of "portable" vary
though, in the strict sense it is used to refer to programs that compile
on *any* platform with a compiler for the respective language. In a
more lax sense, it means programs that compile on a more or less broad
selection of platforms. The latter is more correctly referred to as
"cross-platform".
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.

Programs like Office make heavy use of platform-specific libraries. If
Microsoft would want to, they could have used a cross-platform GUI
library though to make their product compilable for more than just
Windows. Many programs are written that way, OpenOffice.org is one
example to stick with office apps.
I thought only Java offered this WORM (write once, read many) capability
through the client-installed JVM.

The JVM basically provides an abstraction of the underlying platform to
interpret the same compiled bytecode on different platforms. Thereby,
the JVM becomes a platform of itself, running on top of the underlying one.
Do different CPU chips provide different functionality that you must write
for? Do compilers interpret the same way?

Different functionality, different machine code sequences to represent
the same functionality, different byte sequences to represent the same
numeric values etc. plus the respective OS provides different ways to
access facilities like file I/O. Different ways to organise the
compiled executable into (a) file(s) or other storage...
Any insight is appreciated.

HTH,
Malte
 
J

JKop

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
 
J

Jeff

He's "talking the talk"? and thinks HLL is a commonly-used acronym for
High
Level Language?

Yes, HLL was used many times by the instructor to refer to a high level
language. Guess it's not widely used.

Thanks for the clear explanations provided by Malte Starostik and JKop.
 
I

Ioannis Vranos

Jeff said:
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 platforms
(Windows, UNIX, Macintosh) to produce a binary with the same functionality.

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.


They do not want make it available in Unix, because they want to sell
Windows.

MS Office *is* also available in Mac. Internet Explorer was available
too, but I do not know if this one is still.

I thought only Java offered this WORM (write once, read many) capability
through the client-installed JVM.

Do different CPU chips provide different functionality that you must write
for? Do compilers interpret the same way?

Any insight is appreciated.


There are two kinds of portability. Source code portability, that is
source code that compiles with a compiler to create native binaries in
various platforms, and Binary portability, that is binaries that run on
various platforms unchanged.

In general, Source code portability vs Binary portability has the
benefit that the native executables it produces are more efficient than
portable binaries. Portable binaries imply the existence of a virtual
machine, against which they actually run (and the VM then makes the
appropriate native calls).


C++ addresses binary portability in a standardised way, with the
upcoming C++/CLI standard.
 
B

bd

Jeff said:
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 platforms
(Windows, UNIX, Macintosh) to produce a binary with the same functionality.

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.

Heh, it's not that simple. Office uses APIs beyond the C++ API - either
Win32 APIs on windows or whatever MacOS APIs it uses on MacOS. These add
support for GUIs, networking, threads, etc, etc. However, the function and
structure names, as well as the logic needed to use them, vary between
platforms. In order to work on those other platforms, an abstration layer
would need to be created to hide these differences, and that will only
happen if the vendor sees enough interest to "port" the application to the
other platform.
I thought only Java offered this WORM (write once, read many) capability
through the client-installed JVM.

The JVM is an example of an abstraction layer which hides the platform API
details.
Do different CPU chips provide different functionality that you must write
for? Do compilers interpret the same way?

Generally, such low-level details aren't the problem when porting an
application (unless the application in question is part of a compilation
toolchain of some sort, of course)
 

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

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,512
Latest member
FinleyNick

Latest Threads

Top