Previous Next Contents Index Doc Set Home


The C++ Compiler

1


This chapter provides a brief conceptual overview of C++ and the C++ compiler, with particular emphasis on the areas of difference and similarity with C. Chapter 7, "Moving From C to C++," summarizes issues important to C programmers moving to C++.


Operating Environments

For an explanation of the specific operating environments supported in this release, refer to the README file. You can view this file by typing the command

% CC -readme


Standards Conformance

The compiler implements the C++ language as described in the C++ Annotated Reference Manual (ARM). It also conforms to selected extensions of the January 1996 C++ Draft Working Paper (ISO).


Organization of the Compiler

The C++ compiler package consists of a front end, optimizer, code generator, assembler, template pre-linker, and link editor. The CC command invokes each of these components automatically unless you use command-line options to specify otherwise. Figure 1-1 shows the C++ compilation system

Figure 1-1 Organization of the C++ Compilation System.

Table 1-1 summarizes the components of the C++ compilation system.

Table 1-1 Components of the C++ Compilation System 

Component
Description
Notes on Use
ccfe

Front end (Compiler preprocessor and compiler)


iropt

Code Optimizer

(SPARC) -O,
-xO[2-5], -fast

cg386

Intermediate language translator

(x86) Always invoked

cgppc

Intermediate language translator

(PowerPC) Always invoked

inline

Inline expansion of assembly language templates

.il file specified

mwinline

Automatic inline expansion of functions

(x86) (PowerPC)
-xO4,
-xinline

fbe

Assembler

cg

Code generator, inliner, assembler

(SPARC)

codegen

Code generator

(x86) (PowerPC)

tdb_link

Template pre-linker

ld

Non-incremental editor

ild

Incremental link editor

-g,
-xildon

The C++ compiler package also includes:


C++ Tools

Most of the C++ tools are now incorporated into traditional UNIX® tools. These tools are bundled with the operating system. They are:

Please see Profiling Tools and associated man pages for further information on these UNIX tools.


The C++ Language

This version of C++ supports the C++ language as described in The C++ Programming Language by Margaret Ellis and Bjarne Stroustrup, with a few deletions and a number of extensions.

C++ is designed as a superset of the C programming language. While retaining the efficient low-level programming, C++ adds:

This last feature, particularly, allows good design of modular and extensible interfaces among program modules.

Type Checking

A compiler or interpreter performs type checking when it ensures that operations are applied to data of the correct type. C++ has stronger type checking than C, though not as strong as that provided by Pascal. Pascal always prohibits attempts to use data of the wrong type; the C++ compiler produces errors in some cases, but in others converts data to the correct type.

Rather than having the C++ compiler do these automatic conversions, you can explicitly convert between types, just as you can in C.

A related area involves overloaded function names. In C++, you can give any number of functions the same name. The compiler decides which function should be called by checking the types of the parameters to the function call. This action may lead to ambiguous situations. If the resolution is not clear at compile time, the compiler issues an "ambiguity" error.

Classes and Data Abstraction

A class is a user-defined type. If you are a C programmer, think of a class as an extension of the idea of struct in C. Like the predefined types in C, classes are defined not only with data storage but also with operations that apply to the data. In C++, these operations include operators and functions. For example, if you define a class carrot, you can define the + operator so it has a meaning when used with carrots. If carrot1 and carrot2 are objects of the type carrot, then the expression:

carrot1 + carrot2

has a value determined by your definition of + in the case of carrots. This definition does not override the original definition of +; as with overloaded function names, the compiler determines from context what definition of + it should use. Operators with extra definitions like this are called overloaded operators.

In addition to operators, classes may have member functions, functions that exist to operate on objects of that class.

C++ provides classes as a means for data abstraction. You decide what types (classes) you want for your program's data and then decide what operations each type needs.

The members of a class can be divided into three parts: public, private, and protected. The public part is available to any function; the private part is available only to member and friend functions; the protected part is available to members, friends, and members of derived classes.

Object-Oriented Features

A program is object-oriented when it is designed with classes, and the classes are organized so that common features are embodied in base classes, sometimes called parent classes. The feature that makes this possible is inheritance. A class in C++ can inherit features from one base class or from several. A class that has a base class is said to be derived from the base class.

Native Language Support

This release of C++ supports the development of applications in languages other than English, including most European languages and Japanese. As a result, you can easily switch your application from one native language to another. This feature is known as internationalization.

In general, the C++ compiler implements internationalization as follows:

Variable names cannot be internationalized and must be in the English character set.

You can change your application from one native language to another by setting the locale. For information on this and other native language support features, see the operating system documentation.

Compatibility With C

C++ is highly compatible with C. The language was purposely designed this way; C programmers can learn C++ at their own pace and incorporate features of the new language when it seems appropriate. C++ supplements what is good and useful about C; most important, C++ retains C's efficient interface to the hardware of the computer, including types and operators that correspond directly to components of computing equipment.

C++ does have some important differences from C; an ordinary C program may not be accepted by the C++ compiler without some modifications. Chapter 7, "Moving From C to C++," discusses what you must know to move from programming in C to programming in C++.

Even though the differences between C and C++ are most evident in the way you can design interfaces between program modules, C++ retains all of C's facilities for designing such interfaces. You can, for example, link C++ modules to C modules, so you can use C libraries with C++ programs.

C++ differs from C in a number of other details. In C++:




Previous Next Contents Index Doc Set Home