Tuesday, August 18, 2015

C++

C++ is a compiled language. For a program to run, its source text has to be processed by a compiler,
producing object files, which are combined by a linker yielding an executable program. A
C++ program typically consists of many source code files (usually simply called source files).
compiler
Computers understand only one language and that language consists of sets of instructions made of ones and zeros. This computer language is appropriately called machine language.

A single instruction to a computer could look like this:


0000010011110

A particular computer's machine language program that allows a user to input two numbers, adds the two numbers together, and displays the total could include these machine code instructions:

0000010011110
0000111110100
0001010011110
0001111010100
0010010111111
0010100000000

As you can imagine, programming a computer directly in machine language using only ones and zeros is very tedious and error prone. To make programming easier, high level languages have been developed. High level programs also make it easier for programmers to inspect and understand each other's programs easier.

link
 refers to the creation of a single executable file from multiple object files. In this step, it is common that the linker will complain about undefined functions (commonly, main itself). During compilation, if the compiler could not find the definition for a particular function, it would just assume that the function was defined in another file. If this isn't the case, there's no way the compiler would know -- it doesn't look at the contents of more than one file at a time. The linker, on the other hand, may look at multiple files and try to find references for the functions that weren't mentioned.
 An executable program is created for a specific hardware/system combination; it is not portable,
say, from a Mac to a Windows PC. When we talk about portability of C++ programs, we usually
mean portability of source code; that is, the source code can be successfully compiled and run on a
variety of systems.

The ISO C++ standard defines two kinds of entities:

• Core language features, such as built-in types (e.g., char and int) and loops (e.g., for-statements
and while-statements)
• Standard-library components, such as containers (e.g., vector and map) and I/O operations
(e.g., << and getline())
The standard-library components are perfectly ordinary C++ code provided by every C++ implementation.
That is, the C++ standard library can be implemented in C++ itself (and is with very
minor uses of machine code for things such as thread context switching). This implies that C++ is
sufficiently expressive and efficient for the most demanding systems programming tasks.
C++ is a statically typed language. That is, the type of every entity (e.g., object, value, name,
and expression) must be known to the compiler at its point of use. The type of an object determines
the set of operations applicable to it.

No comments:

Post a Comment