A Comparison of System Programming Languages
C, C++ and Ada
C, C++ and Ada
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]
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.
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]
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.
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.
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:
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.
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 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.
Of the three languages, only Ada supports concurrency. However, both C and C++ have been used to develop systems which support concurrency.
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.
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:
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.
[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
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 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: