Thank you. For some reason, I've had a hard time
trying to
understand this (but
then again, I wouldn't say that my programming skills are
at an
advanced level,
and I've not messed with java all that much,
either.)
So what you are saying is that when I "#include" in
a
.cpp, I am
invoking the API dealing with the most basic in/out
functions
of
C++?
Yes, that's definitely correct. The I/O routines and
header
files (like ) are part of the standard library, and any
time you
interact with the standard library in any way, you are
doing so via an
API.
If this is the case, then how can Oracle get away
with saying
"Java is a
language that is free for all to use" and then turn around and
say
"you're not allowed to use any of the java commands?" What is a
language
without commands?
Well, you can have C++ (the core language)
without the C++
standard library. It's more common with C, but you can find it
with C++. Actually there are terms for just such usage in the C
and C++
standards: A hosted implementation and a
freestanding
implementation. Quoting from GCC
documentation:
The ISO C standard defines (in clause 4) two
classes
of conforming implementation. A conforming hosted
implementation supports the whole standard including all the
library
facilities; a conforming freestanding
implementation is only required
to provide certain library
facilities: those in , , , and
; since AMD1, also
those in ; and in C99,
also those in and . In addition, complex
types, added
in C99, are not required for freestanding
implementations. The standard also
defines two environments for
programs, a freestanding environment,
required of all
implementations and which may not have library facilities
beyond
those required of freestanding implementations, where the
handling of
program startup and termination are implementation-
defined, and a hosted
environment, which is not
required, in which all the library facilities
are provided and
startup is through a function int main (void) or int main
(int,
char *[]). An OS kernel would be a freestanding environment; a
program
using the facilities of an operating system would
normally be in a hosted
implementation.
Almost all userspace programs utilize the
standard library and
therefore require a hosted environment. But, for example,
the
Linux kernel (written in C) does not use the standard library; it
doesn't
have, for example, the functions printf() and exit()
(what does it mean for a
kernel to exit?).
Many embedded devices are also programmed using C, and
they
are most often freestanding environments. Where should printf()
send the
printed output if called by a program that runs in, say,
your washing machine?
See, it doesn't make too much sense.
C++ is a bit less frequently seen in
freestanding
environments, but it still happens. For example, the Symbian
operating system is written in C++. Also the Arduino "open-source
electronic prototyping
platform" (a device designed for both
learning embedded programming and for
people with fairly little
programming experience, like artists, who
nevertheless would like
to be able to control some simple hardware like leds in
their
projects) can be programmed in C++. It's essentially a very
inexpensive
board with an AVR microcontroller, a led, a serial
port and free I/O pins where
you can add your own devices to
control or purchase one of several add-on
"shields", like an "LCD
shield", which are designed to plug into the board.
Neither of
those offer the full standard library, nor would many of the
functions in the standard library make sense in such an
environment. [ Reply to This | Parent | # ]
|