C++ (1202/c::003)

C++

Class-based object oriented C  


Stroustrup Bell Labs. An object-oriented superset of C. In C++ a class is a user-defined type, syntactically a struct with member functions. Constructors and destructors are member functions called to create or destroy instances. A friend is a nonmember function that is allowed to access the private portion of a class. C++ allows implicit type conversion, function inlining, overloading of operators and function names, default function arguments, and pass by reference. It has streams for I/O.

C++ release 2.0 - May 1989. Added multiple inheritance, type-safe linkage, pointers to members, abstract classes. "C++ 2.0 Draft Reference Manual"

C++ release 2.1 Added nested types. "The Annotated C++ Reference Manual", M. Ellis et al, A-W 1990.

C++ release 3.0 - Added templates. OOL. Derivative of C, "with classes".Inheritance, polymorphism, encapsulation, data hiding, reusability, etc, are all aspects of C++ and OOL. Very powerful and fast, but considered hard to learn.

Developed by Bjarne Stroustrup, who desribes C++ as "a general-purpose programming language with a bias towards system programming that is better than C; supports data abstraction, OOP, and generic programming". He also said,"within C++, there is a smaller cleaner language struggling to get out".  

"Main problem with C/C++ is that the programmer is required to do their own memory management (to declare variables, explicitly manage pointer-chained lists, dimension buffers and detect or prevent buffer overruns, to allocate and deallocate dynamic storage" Eric S. Raymond.  




People:
Structures:
Related languages
C => C++   Evolution of
C with Classes => C++   Evolution of
C++ => ABC++   Augmentation of
C++ => ACT++   Extension of
C++ => Amber   Based on
C++ => ARTS/C++   Extension of
C++ => C#   Influence
C++ => C++//   Extension of
C++ => C++Linda   Evolution of
C++ => CCC   Extension of
C++ => CHARM++   Based on
C++ => CINT   Interpreter for
C++ => CLANG   Extension of
C++ => Compositional C++   Extension of
C++ => Concurrent C++   Based on
C++ => cooC   Extension of
C++ => COOL   Extension of
C++ => C-XSC   Extension of
C++ => DB++   Extension of
C++ => DEMETER   Augmentation of
C++ => Dylan   Influence
C++ => E   Extension of
C++ => EUROPA   Extension of
C++ => gcc   Implementation
C++ => HPC++   Evolution of
C++ => Hybrid   Influence
C++ => ILU   Interface for
C++ => LiveScript   Influence
C++ => Mars   Optimisation and subset of
C++ => Mentat   Extension of
C++ => OAK   Simplification and enhancement of
C++ => Open C   Evolution of
C++ => P++   Preprocessor for
C++ => pC++   Extension of
C++ => PCP   Extension of
C++ => PK/C++   Extension of
C++ => PROP   Extension of
C++ => Real-Time C++   Augmentation of
C++ => S++   Positive Strong Influence
C++ => Synchronous C++   Extension of
C++ => TBAG   Extension of
C++ => Topsy   Subset
C++ => VCODE   Preprocessor for
C++ => XC   Extension of
C++ => ZQL[C++]   Subsumed

References:
  • Stroustrup, Bjarne "Data Abstraction in C" pp 1701-1732. view details
          in Bell Labs Journal. Vol 63, No. 8. October 1984 view details
  • Stroustrup, Bjarne "Operator Overloading in C++" view details
          in Proc. IFIP WG2.4 Conference on System Implementation Languages: Experience & Assessment September 1984 view details
  • Stroustrup, Bjarne "The C++ Reference Manual" AT&T Bell Labs Computer Science Technical Report No. 108 January 1984 view details
          in Proc. IFIP WG2.4 Conference on System Implementation Languages: Experience & Assessment September 1984 view details
  • Stroustrup, Bjarne "An Extensible i/o Facility for C++" pp 57-70. view details
          in Proc. Summer 1985 USENIX Conference. June 1985 view details
  • Stroustrup, Bjarne "An overview of C++" pp7-18 view details
          in SIGPLAN Notices 21(10) October 1986 (OOPWORK Proceedings of the 1986 SIGPLAN workshop on Object-oriented programming Yorktown Heights, New York, United States) view details
  • Stroustrup, Bjarne "C++ Programming Language" pp71-72 view details
          in IEEE Software 3(01) January 1986 (Multiparadigm language projects) view details
  • Stroustrup, Bjarne "The C++ Programming Language", Addison-Wesley Publishing Co., Inc., Boston, MA, 1986 view details
          in IEEE Software 3(01) January 1986 (Multiparadigm language projects) view details
  • Stroustrup, Bjarne "Multiple Inheritance for C++" view details
          in Proc. EUUG Spring Conference, May 1987. view details
  • Stroustrup, Bjarne "The Evolution of C++" pp 1-22. view details
          in Proc. USENIX C++ conference, Santa Fe. November 1987 view details
  • Stroustrup, Bjarne "What is 'object-oriented programming'?" p51-70 view details
          in European conference on object-oriented programming on ECOOP '87, October 1987, Paris, France view details
  • Stroustrup, Bjarne and Shopiro, Jonathan "A Set of C classes for Co-Routine Style Programming" pp 417-439. view details
          in Proc. USENIX C++ conference, Santa Fe. November 1987 view details
  • Stroustrup, Bjarne "Parameterized Types for C++" view details
          in USENIX Computer Systems, Vol.2 No. 1. 1989 view details
  • Stroustrup, Bjarne "Type-safe Linkage for C++" view details
          in USENIX Computer Systems, Vol 1 No.4. Fall 1988 view details
  • Trickey, Howard "C++ versus LISP: a case study" pp9-18 view details Abstract: A large application program was simultaneously coded in both C++ and Lisp. This note compares the two implementations. The conclusion is that programming in the two languages takes roughly the same amount of time and effort, but C++ seems better for a number of reasons. DOI
          in SIGPLAN Notices 23(02) February 1988 view details
  • Edelson, D. and I. Phol "C++: solving C's shortcomings?" view details
          in Computer Languages 14(3) view details
  • Ladd, Scott Robert "Comparing MODULA-2 and C++" DDJ January, 1989 view details Extract: Intro
    Two of the hottest languages these days are Modula-2 and C++. They appeared in the early 1980s, and both are gaining in popularity. Each was designed and written by a single person: Niklaus Wirth created Modula-2, and C++ was developed by Bjarne Stroustrup. An additional similarity is that both languages are extended versions of earlier languages. This article contrasts Modula-2 and C++; it assumes you have a cursory familiarity with both Pascal and C (the root languages of Modula-2 and C++, respectively). Extract: Modula-2 Background
    Modula-2 Background

    Pascal was designed as a teaching language, to show students how to structure programs properly. It lacks intrinsic support for character strings, file I/O, and separately compiled modules. Pascal has many features that are useful in software development, and the language gradually gained popularity outside the academic community. Unfortunately, the vendors that implemented Pascal did not develop a standard for extending the language to cover its weak points. Thus, every Pascal compiler is unique, and porting programs between implementations is difficult.

    Wirth intended Modula-2 to be the successor to Pascal. Modula-2's name implies one of its basic concepts: modular program design. Through the use of modular facilities, Modula-2 supports data abstraction and encapsulation. All I/O is done through procedures in modules as an aid to portability. As long as the interface to the I/O procedures does not change, the implementation of those procedures can be modified for different environments without having to make alterations in the programs using them.

    Among high-level languages, only Modula-2 and Ada support multiprocessing. In addition, Modula-2 supports bit manipulation, generic types, and system-level access. Modula-2 (unlike Pascal) is well suited to the writing of system software such as operating systems and device drivers.
    Extract: C++ Background
    C++ Background

    C is a powerful system-level language; in its original definition, however, it lacked many features necessary for large, complex projects. Stroustrup designed C++ to amend problems with the C language, in much the same way as Wirth designed Modula-2 to correct the deficiencies of Pascal. C++ provides capabilities for strong type checking, modular programming, and data abstraction while maintaining full compatibility with existing C programs.

    Stroustrup borrowed the object-oriented paradigm from Smalltalk; classes and methods are the most significant additions he added to C in creating C++. In an object-oriented language, objects (data items) belong to classes (types), which have associated methods (functions). "Messages" are sent to objects via their class methods; the messages tell the objects how to act. For example, an object of class int would be given the message "add 1" by the ++ (increment) method. Although this concept can take some getting used to, it can be more appropriate than traditional program design methods.

    C++ is often implemented as a translator. The C++ translator works much like the standard C preprocessor, converting C++ programs into C programs. A C compiler is then run on the output of the translator, producing executable code. By its nature, this process is cumbersome and slow. Recently, manufacturers have released true C++ compilers.

    In addition to adding object-oriented capabilities to C, C++ offers other enhancements, including in-line functions, function prototyping (since added to the ANSI standard), and overloading. Because it retains all C's low-level facilities, C++ can be used for a wide variety of applications. Extract: General Language Features
    General Language Features

    Modula-2 and C++ have the following general features:

    * Source code format -- Source code is case sensitive in C++ and Modula-2. All C++'s keywords must be in lowercase; Modula-2 requires uppercase.

    * Data types -- Both languages are rich in data types and allow the creation of new types. They offer long and short, signed and unsigned, integers and reals. Strings in both languages are handled as arrays of characters terminated by a zero (NUL) byte. Both languages have pointer types. C++ provides the capability to smoothly integrate new types through its class structure, while Modula-2 provides generic types and better control over data item visibility. Modula-2 provides SET types (including BITSET, which allows access to the individual bits of an item), whereas C++ has C's bit structures.

    * Functions and procedures -- Modula-2 has procedures, whereas C++ has functions. The purpose is the same in both languages: to provide callable routines with parameters and local variables. Modula-2 allows the nesting of procedures within procedures, using the same scoping rules as it does for variables. Modula-2 and C++ parameters can be passed either by reference or by value.

    * Control structures -- Here, too, there are no important differences. Although the syntax may vary, the capability is the same. Both languages have loops with tests at both the top and the bottom of the loop. The for, which iterates through a succession of values, is available in both languages. There is (of course) the ubiquitous if ..else ..endif conditional construct. Useful multiple-condition branches (switch in C++ and CASE in Modula-2) are available.

    * Library routines -- C++ uses the standard C library, which is extensive and robust. Wirth defined several standard modules in his definition of Modula-2, but these provided only minimal capabilities. Most Modula-2 vendors have created expanded libraries for their implementations.
    Extract: Unique Features of Modula-2
    Unique Features of Modula-2

    Modula-2 is not a superset of Pascal; rather, it is an evolution of the earlier language. For example, one of Modula-2's most welcome enhancements over Pascal is its simplified block structure. A Modula-2 program is not filled with BEGIN...END pairs; each control structure has an implicit block terminated by an END statement. Where Pascal has functions and procedures (the former returns a value whereas the later does not), Modula-2 simply has procedures. A Modula-2 procedure returns a value if it is specified as doing so.

    One fascinating feature of Modula-2 is its support for coroutines, which are individual processes within a program that run concurrently. This allows multiple tasks (within a program) to be performed simultaneously. A word processor, for example, could use coroutines to allow a document to be printed while another is being edited.

    The strong type checking in Pascal prevents spurious errors but also causes difficulties. For instance, it is impossible to create a general function in standard Pascal that can accept arrays (such as character strings) of different sizes. Modula-2 introduces the concept of the open array parameter -- for example, a parameter to a procedure can be declared as an array without bounds (array of char). Any length array of the specified type (in this case, a character array) can be passed to that function. The procedure can then find out the actual length of the array with the built-in HIGH procedure.

    Modula-2 also provides the generic type. A WORD type is equal in size to the default word size of the hardware it is running on. In the case of MS-DOS, a WORD type is 16 bits long. Any type of the same size (usually the INTEGER and CARDINAL types) is assignment compatible with WORD. An extension of this is that any value can be passed to an open array of type WORD (that is, a procedure parameter of type ARRAY OF WORD). The size of the array is the number of WORD types required to hold the value being passed.

    The concept of modules allows Modula-2 programmers to control access to individually compiled portions of a program. The following object-oriented example illustrates how modules can be used.
    Extract: Unique Features of C++
    Unique Features of C++

    C++ refines and expands C while including all C's strengths. Several features of the emerging ANSI C standard are actually borrowed from C++. Examples of this are function prototypes, const, and void. Function prototypes were added so that C++ could do type checking or arguments; under the original K&R C, values of incorrect types could be passed to functions, often causing obscure errors. Const provides named constants. Adding void allowed the creation of generic pointers and made it possible to declare that a function does not return a value.

    Overloading functions lets the programmers create several functions with the same name but differentiated by their parameters. Instead of C's current crop of absolute value functions (abs, dabs, fabs, and labs), a C++ implementation could have the following:

    overload abs; int abs(int i); long abs(long l); float abs(float f); double abs(double d);
    At compile time, the C++ compiler determines which version of abs to use based on the parameters it is being passed. This facility can make programs easier to understand.

    It is possible to overload operators in C++. You can, for instance, create a new class that can use the same operators as existing classes. The section on object-oriented programming later in this article contains an example of operator overloading.

    The object-oriented features of C++ are prominent. Object-oriented programming requires a change in thinking for many programmers; instead of thinking in terms of the nuts and bolts of programming, programmers are required to visualize a program as a series of processes applied to data items. This may seem to be a subtle distinction, but it must be mastered to truly appreciate and use an object-oriented language. The object-oriented features of C++ are illustrated in the section on the subject in this article.

    C++ provides dozens of other extensions to C, including in-line functions, anonymous (unnamed) unions, and default function parameter values. There are dangers to the many features provided by C++. Whereas C has always been famous for providing the rope by which programmers hang their programs, C++ adds the noose. Care must be taken to avoid "going wild," especially with the overload capabilities.
    Extract: Conclusion
    Conclusion

    Modula-2 and C++ are powerful languages; both have bright futures. C++'s classes, methods, and overloading make it a powerful tool, but it has few restraints to keep programmers from being too "creative." Modula-2 is a strongly organized language with restraints to keep programmers within guidelines. It is not as extensible as C++, but it does implement its own unique features, such as SETs, coroutines, and open arrays. Which of these languages is more appropriate for a specific project will depend on the type of application and the experience of the programmers involved. Both languages are powerful and interesting to work with.

          in Computer Languages 14(3) view details
  • Stroustrup, Bjarne "Multiple Inheritance for C++" view details
          in USENIX Computer Systems, Vol 2 No 4, Fall 1989 view details
  • Stroustrup, Bjarne "Standardizing C++" view details
          in The C++ Report. 1(1) January 1989 view details
  • Ellis, M. et al, "The Annotated C++ Reference Manual", A-W 1990. view details
          in The C++ Report. 1(1) January 1989 view details
  • Liu, Chung-Shyan "On the object-orientedness of C++" pp63-67 view details Abstract: In this note, two different definitions of object-oriented programming, whether a class is equivalent to a type or not, will be presented. Then the relative merits of the two definitions, regarding encapsulation of objects, type checking, genericity, and inheritance of objects, will be discussed. In particular, a C++ sample program will be given to illustrate that the encapsulation of objects may be violated. DOI
          in SIGPLAN Notices 26(03) March 1991 view details
  • Stroustrup, Bjarne "The C++ Programming Language", Second Edition, Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 1991 view details
          in SIGPLAN Notices 26(03) March 1991 view details
  • Abadi, Martin and Cardelli, Luca "A Theory of Objects" Springer Monographs in Computer Science, 1996 view details

          in SIGPLAN Notices 26(03) March 1991 view details
  • Bjarne Stroustrup "A HISTORY OF C++: 1979-1991" in "History of Programming Languages", ACM Press/Addison-Wesley Publishing Company, New York (1996) ed Bergin and Gibson view details
          in SIGPLAN Notices 26(03) March 1991 view details
  • Stroustrup, Bjarne "The C++ Programming Language", Third Edition, Addison-Wesley Longman Publishing Co., Inc., Boston, MA, 1997 view details
          in SIGPLAN Notices 26(03) March 1991 view details
  • Library of Congress Subject Headings C153 view details
          in SIGPLAN Notices 26(03) March 1991 view details
    Resources

    • "
    • C++