CS 610 Final Project

A Comparison of System Programming Languages

C, C++ and Ada

 


  • Abstract
  • Introduction
  • Related Research
  • "Open" Operating systems
  • The C Programming Language
  • The C++ Programming Language
  • The Ada Programming Language
  • Systems Programming Experiences
  • Language Comparisons
  • Language Design
  • Methodology
  • Results and Conclusions
  • Arrays
  • Pointers
  • Concurrency
  • Object orientation
  • Discussion
  • References
  • Bibliography
  • Appendix: Research Experience


  •  

     

    A Comparison of System Programming Languages

    C, C++ and Ada

    Abstract This report is a study of C, C++ and Ada as system programming languages. A review of literature to reveal characteristics needed by a "good" systems programming language to be used as a standard of comparison was of limited success. However, certain themes concerning the differences between the three languages did arise. The three languages are compared against this standard and the relevance of the differences is assessed Introduction The assertion that certain languages are superior for certain purposes, such as systems programming, is widely made. Pratt and Zelkowitz support this idea in their discussion of what makes a good computer language [PRAT96]. The topic is also frequently debated in "My language is better than your language" flame-wars on the USENET news groups, generally with less objectivity than Pratt and Zelkowitz. One purpose for which programming languages are used is systems programming – the development of operating systems and supporting software. Early operating systems were written primarily in assembler, but modern systems are generally written in higher level languages [PRAT96]. Among the languages actually used to develop system software are C, which is the primary language to develop UNIX®® [GOOD94], and C++, which was used by IBM to develop system software for the AS400 [SOLT96]. Ada, which was developed by the Department of Defense to support embedded systems, would seem a likely candidate for a systems programming language, but has not enjoyed success as such [PRAT96]. Whether the failure of Ada to achieve success in the systems programming realm is due to technical, marketing or other considerations is an interesting question, but too broad for this investigation. This report provides a technical analysis of the three languages as systems programming languages. Related Research The UNIX® operating system is widely documented in such books as The Magic Garden Explained [GOOD94]. The C programming language is widely documented in such books as The C Programming Language [KERN88] and is subject to an ISO/ANSI Standard [ANSI89]. C++ is documented in The C++ Programming Language [STRO97] and is the subject of a proposed standard [ANSI96]. Ada is subject to an ISO/ANSI Standard adopted in 1995 and documented the Ada Reference Manual [INTE95].

    "Open" Operating systems

    Normally operating systems are developed as commercial ventures – either by a hardware manufacturer to support its proprietary machines (e.g., IBM mainframes) or by an independent software developer (e.g. Microsoft). In any case, operating systems developers have been traditionally unwilling to share architectural details, much less actual source code. Even supposedly "Open" UNIX® is subject to proprietary source code and licensing restrictions [GOOD94]. However, recently there have been efforts to develop serious operating systems with publicly available source code. One of the more successful of these efforts is Linux.

    Linux is the product of a Finnish Computer Science student named Linus Torvalds. What started as a "hobby project" to improve on MINIX has become a full-fledged UNIX® clone with a full set of services, including networking, X Window, programming environments and a growing body of commercial software. [WELS95] Like Commercial UNIX®, Linux is written primarily in C. [BECK96]

    The C Programming Language

    C was written by Dennis Ritchie at Bell Laboratories as a language to develop the UNIX® operating system[SEBE89]. The language arose out of a need for a high level language that would work within constrained memory, but provided more features than the previous language B, also developed at Bell Laboratories. To B, C added types, structure definitions and more operators [PRAT96]. C is subject to an ANSI standard adopted in 1989 [ANSI89]. Sebesta [SEBE89] describes C as having an adequate set of control and data structures, but a rich set of operators. Pratt and Zelkowitz [PRAT96] describe C as the "C concept." The language itself is small but it is almost always used with a preprocessor, header files that document interface assumptions and a large standard library.

    The C++ Programming Language

    C++ began as a tool to assist Bjarne Stroustrup in an analysis of how the UNIX® kernel could be distributed over a network of computers. The earliest version was a preprocessor which added classes, a concept taken from Simula, to C. He now thought of his tool as a language, which he called "C with Classes." His primary goals were to add to C the capability to express modularity and concurrency. The lack of specific concurrency primitives was a deliberate design decision to allow support of multiple models. C with Classes was successful enough that Stroustrup decided to create a full fledged language which was eventually named C++. [STRO94]

    The Ada Programming Language

    Ada was designed and standardized before there was a working compiler. One result of this process is that work on a revision began shortly after the first effective translators appeared. [PRAT96]. Ada provides for modularity via packages, hierarchical arrangement of modules, concurrent tasks, strong typing, a variety of elementary and composite data types, user defined subtypes and derived types, object oriented programming with run-time polymorphism, access to variables, constants, objects and subprograms, generic parameters, interfaces to other languages and special annexes to support Systems programming, Real-Time systems, Distributed Systems, Information systems, Numerics and Safety and Security. [INTE95]

    Systems Programming Experiences

    Nakao, Kinjo and Nakama [NAKA93] performed a similar study in 1993, but limited to Ada and C. This was before the finalization of the Ada 95 Standard and did not consider object oriented extensions made possible by C++ and Ada 95. As part of their research they translated the educational operating system, MINIX, into Ada. One of their findings was that the structure of MINIX is so closely related to C that it was difficult to describe some of its features in Ada.

    Madany, Campbell and Kougiouris built an experimental operating system (Choices) using C++. They determined that there are unique capabilities provided by this approach [MADA91]. Although there was not direct language support for all of the desired features, they were able to construct the necessary operations from C++ primitives.

    Erlingsson and Konstantinou proposed an Ada 95 implementation of the C++ Standard Template Library [ERLI96]. They determined that such a project was feasible and that Ada holds some advantages in terms of strong typing and explicit instantiation of generic packages and functions. On the other hand, they admitted that, due to certain Ada restrictions on pointers and overloading, achieving orthogonality with regard to built in types would not be easy.

    Crenshaw [CREN91] found that object oriented techniques produced an improved compiler design derived from the Backus Naur Form (BNF) language description.

    Language Comparisons

    Reifer maintains software engineering data from various governmental and commercial organizations relative to the cost reliability and maintainability of systems developed using C, C++ and Ada.[REIF96] His data is insufficient with respect to Ada 95, but tends to indicate that Ada 83 is more expensive to produce but more error proof and more reliable than C or C++.

    Lawlis developed a set of "Guidelines for Choosing a Computer Language."[LAWL96] As part of the larger problem of developing a language selection process, she rated several languages according to 13 characteristics. Lawlis rated Ada and C++ generally higher than C, especially in terms of maintainability, reliability, reuseability, safety and support of software engineering. C++ was rated lower than Ada in reliability and safety and slightly lower in maintainability.

    One of the single largest, most comprehensive efforts to define language requirements was the Department of Defense High Order Language Working Group of the late 1970’s. The final product of this effort was a requirements document known as "Steelman" [DOD78] which resulted in the development of Ada. Wheeler [WHEE96] compared Ada 95, C, C++ and Java to the Steelman requirement. Not surprisingly, Ada was the most compliant. The major differences noted by the author were that C and C++ do not directly support concurrency and C does not feature exception handling and generally has minimal support for reliability, maintainability or the detection of errors.

    Rogers [ROGE97] developed a simple comparison between Ada and C++ features. This consists of 54 pairs of statements such as:

    All C++ operators may be overridden.
    The Ada assignment operator cannot be overridden.
     

    Syiek [SYIE95] compared the performance of Tartan Ada and Texas Instruments C to Tartan C over a series of benchmarks. The results showed greater differences between the two C compilers than between Tartan Ada and Tartan C. The Ada performance was slightly better, which the author attributed to four characteristics of Ada semantics which aid compiler optimization:
      The Ada compilation model
    Handling of arrays
    C’s extensive dependence on pointers
    For loop semantics
     
    Language Design

    Pratt and Zelkowitz [PRAT96] specify eight attributes of a good language. One of these is "Naturalness for the application." The language should match the problem to be solved in four areas:
     

    Data structures
    Operations
    Control structures
    Syntax

     

    Methodology This is primarily secondary research. Reference material was obtained by browsing available library volumes for relevant material, by seeking out known authorities, by querying bibliographic databases and by chaining references.

    To begin my research I checked the Southern Polytechnic Library for references on "systems programming." This produced meager results so I expanded the search to references on Operating Systems and program language design and found several useful references.

    In any area there are authorities whose thoughts must at least be considered: texts by Silbershatz and Galvin [SILB94] and Tanenbaum [TANE92] are considered classics; Bjarne Stroustrup is still the authority on C++; etc. So I sought out books by these authorities and looked for Web pages.

    I searched bibliographic databases such as Galileo, Hypatia and the Computer Science Bibliography using queries such as "operating system programming language." I found that "system programming" produced large quantities of irrelevant data.

    Another good source of references, is the references you already have. Frequently the bibliographies and reference sections of the papers and books you have already found contain even better sources of information.

    Initially, the effort was to develop sources which dealt with the development of operating systems and the associated programming problems and requirements. As this approach proved infertile, I expanded the field to include language comparisons and work by language developers.

    Results and Conclusions While various comparisons and conversion attempts have demonstrated a number of differences between the three languages, four stand out as providing a strong philosophical contrast between the three:
      Arrays
    Pointers
    Concurrency
    Object orientation.
     
    Arrays

    All three languages allow for multidimensional arrays. C and C++ require that the index be an integer in the range 0..size-1. Arrays in C and C++ are closely related to pointers and pointer arithmetic can be used to access array elements. Ada allows integer indices but does not restrict to a specific range. In addition, Ada allows the use of enumeration types as array indices. Ada is more strongly differentiated from C and C++ in the handling of arrays as parameters to function and procedure calls. Ada provides a call by reference mechanism whereas C and C++ implicitly convert to a pointer and in the process disable the receiving function from all knowledge of the length of the array.

    Pointers

    Pointers are used extensively in C and C++. Kernighan and Ritchie [KERN88] refer to pointers as "central to C programming." C and C++ pointers may be added to and subtracted from. They can be converted between types. C++ also provides references which are similar to Ada access variables. Ada access variables can point to variables, constants and subprograms, but do not allow pointer arithmetic and are not easily converted from one type to another.

    Concurrency

    Of the three languages, only Ada supports concurrency. However, both C and C++ have been used to develop systems which support concurrency.

    Object orientation

    Ada and C++ support object orientation. C does not. To build object orientation into C would give you C++.

    Incorporation of language features into the operating system creates something of a "chicken and egg" problem. When converting MINIX from C to Ada [NAKA93] or the C++ Standard Template Library to Ada 95 [ERLI96], difficulties with constructs unique to the original language do not necessarily imply shortfalls in the second language. If the program had been written in the second language first, the problems might have been resolved in a way difficult to port to the first language.

    Discussion There is less research in this area than I had imagined.

    What seems clear from all of this is that the choice of systems programming language will strongly influence the design of the language and the way in which problems are solved. The words of Bjarne Stroustrup [STRO97], though written with respect to C++, can be applied to any language:
     

    Thoughtlessly applying techniques effective in one language to another typically leads to awkward, poorly performing, and hard-to-maintain code. Such code is also most frustrating to write because every line of code and every compiler error message reminds the programmer that the language used differs from the "old language." You can write in the style of Fortran, C, Smalltalk, etc., in any language, but doing so is neither pleasant nor economical in a language with a different philosophy. Every language can be a fertile source of ideas of how to write C++ programs. However, ideas must be transformed into something that fits with the general structure and type system of C++ in order to be effective in the different context. Over the basic type system of a language, only Pyrrhic victories are possible.
     
    Clearly the differences between the three languages are deeper than a simple features list with check boxes. Differences such as the treatment of pointers permeate the languages and their approach to problem solutions. Nevertheless, it is not clear that the differences significantly strengthen or weaken any of the languages as systems programming languages, with the exception of object orientation. Several authors [CREN91] [MADA91] have found object orientation to improve the production of systems software.

    The experience of Nakao, Kinjo and Nakama [NAKA93] with MINIX demonstrates that the philosophy of the language permeates the software written with it. Does this mean that one language is necessarily superior to others for system programming? It can if the systems programming task is to write software for an existing operating system. In this case the ability of the programming language to communicate with the operating system may be dependent on its ability to understand the data structures of the language the operating system is written in. Ada provides facilities to import data structures from other languages, C and C++ do not. Therefore, Ada programs for C/C++ operating systems are relatively straight forward, but the ability to write C or C++ programs for an Ada operating system might be less simple. Of course there are no Ada operating systems.

    C and C++ are proven systems programming languages. Ada has been proven in field such as communications and avionics as well as applications programming. This would imply a capability to write systems programs.

     

    References [ANSI89] American National Standards Institute (ANSI), American National Programming Language C, X3.159, ANSI New York, 1989.

    [ANSI96] American National Standards Institute (ANSI). Working Paper for Draft Proposed International Standard for Information Systems—Programming Language C++. 2 December 1996.

    [BECK96] Beck, Michael, et. al. Linux Kernal Internals. Edinburgh Gate, England: Addison Wesley Longman, 1996.

    [COHE96] Cohen, Norman H. Ada as a Second Language, Second Edition. New York: The McGraw-Hill Companies, Inc., 1996.

    [CREN91] Crenshaw, Jack W. "A Perfect Marriage," Computer Language, 8:6(44-55), June 1991.

    [DOD78] Department of Defense, Advanced Research Projects Agency. Requirements for HighOrder Computer Programming Languages—"STEELMAN", 1978.

    [ERLI96] Erlingsson, Úlfar and Konstantinou, Alexander V. "Implementing the C++ Standard Template Library in Ada 95," Rensselaer Polytechnic Institue, Computer Science Department, Technical Report 96-3, 1996. Internet Url: http://www.adahome.com/Resources/Papers/General/stl2ada.ps.Z

    [GOOD94] Goodheart, Berny and Cox, James. The Magic Garden Explained: The Internals of UNIXâ System V Release 4 An Open Systems Design. New York: Prentice Hall, 1994.

    [INTE95] Intermetrics. Information technology—Programming language—Ada. International Standard ISO/IEC 8652:1995(E).

    [KERN88] Kernighan, Brian W., and Ritchie, Dennis M. The C Programming Language, Second Edition. Englewood Cliffs, New Jersey: Prentice Hall, 1988.

    [LAWL96] Lawlis, Patricia K. "Guidelines for Choosing a Computer Language: Support for the Visionary Organization," March 1996. Internet URL: http://www.sw-eng.falls-church.va.us/AdaIC/docs/reports/lawlis/word

    [MADA91] Madany, Peter W., Campbell, Roy H., and Kougiouris, Panos. "Experiences Building an Object-Oriented System in C++," Technical Report TR 91-1671, Department of Computer Science, University of Illinois at Urbana-Champaign, 1991. Internet Url: http://choices.cs.uiuc.edu

    [NAKA93] Nakao, Zensho, Kinjo, Masaya and Nakama, Masahiro. "Ada and C: Differences as the language for systems programming," Ada Letters 13:5(22-31), 1993

    [PRATT96] Pratt, Terrence W. and Zelkowitz, Marvin V. Programming Languages: Design and Implementation, Third Edition. Upper saddle River, New Jersey: Prentice Hall, 1995.

    [REIF96] Reifer, Donald J. "Quantifying the Debate: Ada vs. C++," Crosstalk 9:7, July 1996. Internet Url: http://www.stsc.hill.af.mil/crosstalk/1996/jul/

    [ROGE97] Rogers, Jim. "Comparison of Ada and C++ Features." Internet Url: http://www.adahome.com/articles/1997-03/ada_vs_cpp.html

    [SEBE89] Sebesta, Robert W. Concepts of Programming Languages. Redwood City, California: The Benjamin Cummings Publishing Company, Inc., 1989.

    [SILB94] Silberschatz, Abraham and Peter B. Galvin. Operating System Concepts, Fourth Edition. Reading Massachusetts: Addison-Wesley Publishing Company, 1994.

    [SOLT96] Soltis, Frank G. Inside the AS/400, Duke Press, Loveland, Colorado, 1996.

    [STRO94] Stroustrup, Bjarne. The Design andEvolution of C++. Reading, Massachusetts: Addison-Wesley Publishing Company, 1994.

    [STRO97] Stroustrup, Bjarne. The C++ Programming Language, third edition. Reading, Massachusetts: Addison Wesley Longman, Inc., 1997.

    [SYIE95] Syiek, David. "C vs Ada: Arguing Performance Religion," ACM Ada Letters, 15:6 (67-69), November/December 1995.

    [TANE92] Tanenbaum, Andrew S. Modern Operating Systems. Englewood Cliffs, New Jersey: Prentice Hall, 1992.

    [WELS95] Welsh, Matt and Kaufman, Lar. Running Linux. Sebastopol, California: O’Reilly & Associates, Inc., 1995.

    [WHEE96] Wheeler, David A. "Ada, C, C++, and Java vs. The Steelman." 1996, Internet Url: http://www.adahome.com/History/Steelman/steeltab.htm

     

    Bibliography Aho, Alfred V., Sethi, Ravi and Ullman, Jeffrey D. Compilers: Principles, Techniques and Tools. Reading, Massachusetts: Addison-Wesley Publishing Company, 1985.

    Beck, Leland L. System Software: An Introduction to Systems Programming. Reading, Massachusetts: Addison Wesley Longman, 1997.

    Cabrera, Luis-Felipe and Islam, Nayeem, eds. Fifth International Workshop on Object Orientation in Operating Systems. Los Alimitos, California: IEEE Computer Society Press, 1996.

    Campbell, Roy H., Johnston, Gary M., Madany, Peter M., and Russo, Vincent F. "Principles of Object-Oriented Operating System Design," Technical Report UIUCDCS-R-89-1510, Department of Computer Science, University of Illinois at Urbana-Champaign, April 1989. Internet Url: http://choices.cs.uiuc.edu

    Cugini, John V. General Purpose Programming Languages. Princeton, New Jersey: Petrocelli Books, 1987.

    Finkel, Raphael A. An Operating Systems Vade Mecum. Englewood Cliffs, New Jersey: Prentice-Hall, 1986.

    Hsieh, Wilson C., Fiuczynski, Marc E. Garrett, Charles, Savage, Stefan, Becker, David, and Bershad, Brian N. "Language Support for Extensible Operating Systems," Workshop for Compiler Support for System Software, February 23-24, 1996. Internet Url: http://www.cs.arizona.edu/wcss96/final_pgm.html

    Hudak, Paul and Jones, Mark P. "Haskell vs. Ada vs. C++vs. Awk vs. … An Experiment in Software Prototyping Productivity," July 4, 1994. Internet Url: ftp://nebula.systemsz.cs.yale.edu/pub/yale-fp/papers/NSWC/jfp.ps

    Intermetrics. Information technology—Programming language—Ada: Annotated Ada Reference Manual. International Standard ISO/IEC 8652:1995(E), Version 6.0, 21 December 1994.

    Johnston, Michael K. Linux INFO-SHEET (part 1/1), 20 Jan 97. Internet newsgroup: comp.answers

    Jolitz, William Fredrick and Jolitz, Lynne Greer. "Porting UNIX to the 386: A Practical Approach," Dr. Dobbs Journal, 16:1 (16-46) January 1991.

    Kempe, Magnus. Learning Ada: Frequently Asked Questions (FAQ). 31 May 1996. Internet Url: http://www.adahome.com/FAQ/

    Lapin, J. E. Portable C and UNIXâ System Programming. Englewood Cliffs, New Jersey: Prentice-Hall, 1987.

    Madany, Peter W., Leyens, Douglas E., Russo, Vincent F., and Campbell, Roy H. "A C++ Class Hierarchy for building UNIX-Like File Systems," Proceedings of the USENIX C++ Conference, pp65-79, Denver, Colorado, October 1988. Internet Url: http://choices.cs.uiuc.edu

    Melton, Austin. Software Measurement. London: International Thomson Computer Press, 1996.

    Naiditch, David J. Rendezvous with Ada 95, Second Edition. New York: John Wiley & Sons, Inc., 1995.

    O’Sullivan, Bryan. Comp.os.research: Frequently answered questions. 13 August 1996. Internet newsgroup: comp.answers

    Russo, Vincent F., Madany, Peter W., and Campbell, Roy H. "C++ and Operating Systems Performance: A Case Study," 1990 USENIX C++ Conference, pp103-114, San Francisco, CA, April 1990. Internet Url: http://choices.cs.uiuc.edu

    Spinellis, Diomidis. "Trace: A Tool for Logging Operating System Call Transactions," Operating Systems Review, 28(4):56-63, October 1994.

    Stallings, William. Operating Systems, Second Edition. Upper Saddle River, New Jersey: Prentice-Hall, 1995.

    Stansifer, Ryan. The Study of Programming Languages. Englewood Cliffs, New Jersey: Prentice Hall, 1995.

    Stroustrup, Bjarne. "A Perspective on ISO C++," The C++ Report, 7:8(22-28), October 1995. Internet Url: http://www.research.att.com/~bs/papers.html

    Stroustrup, Bjarne. "Why C++ is not just an Object-Oriented Programming Language," OOPS Messenger, 6:4(1-13), October 1995. Internet Url: http://www.research.att.com/~bs/papers.html

    Taft, S. Tucker. "Programming the Internet in Ada 95 (submitted to Ada Europe ’96)," March 15, 1996. Internet URL: http://www.inmet.com/~stt/adajava_paper/

    Wasserman, Anthony L., ed. Tutorial Programming Language Design. New York: Computer Society Press, 1980.

    Wilkes, Maurice. "Operating Systems in a Changing World," Operating Systems Review, 28(2):9-21, April 1994.

    Appendix: Research Experience

    The more I deal with Microsoft word, the more I miss Wordstar.

    The first lesson I learned was, never upgrade your computer in the middle of the quarter. This cost me at least two weeks of valuable – irreplaceable – time. Adding a new hard drive seemed like a reasonably simple operation, but it wound up costing me all the data on my existing drive.

    I had a great deal of difficulty finding the type of references I wanted to support my information goal of building a standard against which to compare the three languages. This lead to an over extension of the time devoted to gathering references. Which lead me to abandon my original intention to build to convert a Linux systems program from C to Ada. I still think this would be an interesting project: I would first do a relatively straight-forward conversion, perhaps using a C to Ada translator – and then rewrite the converted Ada program using Ada programming concepts. I had even selected the program: traceroute, a relatively small but highly useful networking tool.

    Using the information that I did find, I have come to a number of conclusions that I consider too personal or too subjective to include in the body of the paper: