| A|B |C | D | +-----+. Apr 28, 2014 and will not be copied or posted on any network computer or broadcast in any media, and (2) no modifications of the document is made. Multiply two C variables and assign the result to a third C variable. Data type it will be replaced by the text "pizza with cheese and sparkling water". The left hand.">
1 Fejora

Memcpy Vs Assignment Pointers Pizza


Abstract

This paper compares four computer programming languages (Ada95, C, C++, and Java) with the requirements of "Steelman", the original 1978 requirements document for the Ada computer programming language. This paper provides a view of the capabilities of each of these languages, and should help those trying to understand their technical similarities, differences, and capabilities.

Introduction

In 1975 the U.S. Department of Defense (DoD) established a "Common High Order Language" program with the goal of establishing a single high order computer programming language appropriate for DoD embedded computer systems. A High Order Language Working Group (HOLWG) was established to formulate the DoD requirements for high order languages, to evaluate existing languages against those requirements, and to implement the minimal set of languages required for DoD use. The requirements were widely distributed for comment throughout the military and civil communities, producing successively more refined versions from Strawman through Woodenman, Tinman, Ironman, and finally Steelman. Steelman was released in June 1978 [DoD 1978]. An electronic version of Steelman is available at "http://www.dwheeler.com/steelman". The original version of the Ada computer programming language was designed to comply with the Steelman requirements.

Today there are a number of high order languages in commercial and military use, including Ada95, C, C++, and Java. I thought it would be an interesting and enlightening exercise to compare these languages to Steelman; this paper provides the results of this exercise. Other comparisons of these languages do exist (for example, [Sutherland 1996, Seidewitz 1996]), but none use the Steelman requirements as a basis.

This paper compares four computer programming languages (Ada95, C, C++, and Java) with the requirements of "Steelman". The paper first describes the rules used in this comparison of these four languages with Steelman. This is followed by conclusions summarizing how each language compares to Steelman. After the references is a large table, the "meat" of this paper, showing how each of these languages compare to each of the Steelman requirements.

This paper does not attempt to determine if the Steelman requirements are still relevant. In the author's opinion, most of the Steelman requirements are still desirable for general-purpose computer languages when both efficiency and reliability are important concerns. Steelman is no doubt incomplete; in particular, object-orientation is not a Steelman requirement but is widely considered desirable. However, desirability and completeness need not be true for this comparison to be useful, because this paper simply uses Steelman as a framework for examining technical issues of these computer languages. Steelman is a useful framework because it was widely reviewed and is technically detailed.

Rules for Comparison

The primary rule used in this paper is that a language provides a feature if:

  1. that feature is defined in the documents widely regarded as the language's defining document(s), and
  2. that feature is widely implemented by compilers typically used for that language with essentially the same semantics.

Features that are only provided by a single implementation, or are defined but cannot be depended upon across the most commonly used implementations, are not considered to be part of the language. Examples of features that cannot be depended on are features which are often unimplemented, implemented incorrectly on widely-used compilers, or implemented with significantly differing semantics. Subset compilers for research or student work are not considered unless they are widely used by users of that language. One area where some "benefit of the doubt" is given is for C++ templates. C++ templates are part of the C++ language definition, but current C++ compilers implement templates with different semantics [FSF 1995] and with different levels of quality [OMG 1995]. As a result, C++ templates are currently difficult to use in a portable way. Still, credit is given for C++ templates since the intent is clear and they can be used today (with trouble) on most compilers.

The defining documents used for each of these languages are as follows:

  • Ada95: The "Ada 95 Reference Manual" (referred to as the Language Reference Manual, or LRM) [ISO 1995] is the official definition of Ada95. This document is freely available as a hypertext document at "http://www.adahome.com/rm95/". Ada95 is a revision of the original Ada language (now called Ada83), which added support for object-orientation and various other capabilities. The rest of this paper will use the term "Ada" to mean "Ada95".
  • C: The official current definition of C is ISO/IEC 9899:1990, which is essentially the same as the definition developed by ANSI as ANSI X3.159-1989 [ANSI 1989]. This has been extended by Normative Addition 1 to support internationalization features, as described at "http://www.lysator.liu.se/c/na1.html". Programmers often don't have these costly standards documents; instead, they often use the book by C's developers, Kernighan and Ritchie [Kernighan 1988], so this book is also considered a defining document, along with its errata (see "http://www.lysator.liu.se/c/c-errata.html").
  • C++: There is ongoing work to standardize C++ by 1998 but no final, approved standard. I have used the documents closest to a standard yet widely available, namely, the Working Paper of ISO Working Group WG21 (April 28, 1995). WG21 is developing the International Standard for the C++ programming language. This document is available at "ftp://ftp.research.att.com/dist/c++std/WP/". and an HTML version is available at "http://www.cygnus.com/misc/wp/". There are more recent versions of this document, but access to these revisions is more restricted, and changes from this widely-available version are less likely to be fully implemented in a wide number of compilers. Two other key defining C++ documents are the older books The Annotated C++ Reference Manual (ARM) [Ellis 1990] and Stroustrup's The C++ Programming Language [Stroustrup 1991]. In July 1994 the ANSI/ISO C++ Standards committee voted to adopt the Standard Template Library (STL) as part of the C++ library, so the STL is considered part of C++ in this paper. Other useful C++ references can be found at "http://yoyodyne.tamu.edu/oop/oopcpp.html".
  • Java: The current defining documentation on Java is the documentation set available from Javasoft (a Sun Microsystems business) at "http://java.sun.com/doc/language.html". Note that what is being evaluated here is the Java language, not the underlying Java Virtual Machine. There is already a compiler (by Intermetrics) that takes Ada source code and generates Java Virtual Machine code (see "http://www.dwheeler.com/lovelace/java.htm").

Conclusions

The appendix shows how well each language supports each Steelman requirement.

The following table shows the number of Steelman requirements met by each language. The leftmost column shows the name of the language. The next columns are the number of requirements the language does not meet, only partially meets, mostly meets, and completely meets. The final column shows the percentage of Steelman requirements mostly or completely met by the language. Note that Ada meets the most, followed by Java, C++, and C in that order. The Java and C++ percentages are probably too close to be considered significantly different.

Language "No" "Partial" "Mostly" "Yes" Percentage of Answers with "Mostly" or "Yes"
Ada35119493%
C3221164453%
C++1917235468%
Java2012225972%

Caution is warranted, since differing percentages of "yes" values do not necessarily imply that a particular language is more suitable than another for a given specific task. Note that the original version of Ada was specifically designed to meet the Steelman requirements, while none of the other languages were specifically designed to do so, so it is expected that Ada would meet more of the Steelman requirements than the rest. Also, all of these languages have capabilities that are not Steelman requirements. For example, direct support for object-orientation is a feature of Ada, C++, and Java, but is not a Steelman requirement. Readers should use this comparison to gain additional understanding of each of these different languages, and determine which "yes" and "no" values are of importance to them.








The following are high-level remarks comparing each language to Steelman based on the table in the appendix, including remarks on the language support for reliability (requirement 1B):

  • Ada has the most "yes" responses to Steelman; this is no surprise, since Ada83 was designed to meet the Steelman requirements, and Ada95 is a superset of Ada83. Ada has "no" responses to only 3 Steelman requirements: 3-3F, 5D, and 10F. Requirement 3-3F requires a specific syntax for constants and functions that Ada does not support. Requirement 5D restricts the kinds of values supported by the language. Ada83 complied more fully with requirement 5D (e.g. by not permitting access values to functions), but this Steelman requirement was found to be too restricting. Ada95 removed these restrictions, resulting in noncompliance with Steelman requirement 5D. Steelman requirement 10F requires simple assertion capabilities. Run-time assertions can be trivially implemented in Ada, but Ada does not provide a built-in construct for them. Some Steelman requirements are only supported by Ada, for example, fixed-point types (requirements 3-1G and 3-1H).
  • C does not have a number of the Steelman capabilities. C does not have support for controlling concurrency - calls to the local operating system must be used instead. C also does not have an exception handling system nor generic processing (setjmp/longjmp and preprocessor commands can perform similar actions in trivial cases, but they are not practical substitutes in larger programs). Probably a more fundamental issue is that, while good programs can be written using C, C does not substantially aid in reliability nor maintainability, and does not try to maximize compile-time detection of errors. Those who believe otherwise need only compare C's error detection capabilities with C++, Java, and Ada.
  • C++ supports exception handling and templates (generics), although at this time using C++ templates is problematic. C++ does not support concurrency directly, taking the same approach to this as C does. C++ does try to detect more errors at compile-time than C does by tightening up C's type system somewhat.
  • Java supports exception handling and concurrency, and in general tries to detect errors at compile time. Java does not support enumerated types nor generics (templates). The former can be partly simulated with a long series of constants, and the latter with Java interfaces and the root Object type, but neither are very good mechanisms for simulating these capabilities. These weaknesses are well-known; for example, "Pizza" is superset of Java that adds templates and other capabilities (see "http://wwwipd.ira.uka.de/~odersky/papers.html#Pizza" ). Java does not provide direct control of low-level hardware (such as the size and bit structure of types), since it was not designed for that purpose. Java does try to provide good compile-time and run-time protection; some of the "no" answers in the table are specifically because of this (for example, Java initializes all variable values which goes against requirement 5E and the efficiency issues of requirement 1D). Like Ada, Java does not have a built-in run-time assertion mechanism (requirement 10F), but this is trivially implemented in Java.

Again, users of this paper should apply caution; differing percentages of "yes" values and capabilities do not necessarily imply that a particular language is more suitable than another for a given specific task. Readers should examine each answer and determine which "yes" and "no" values are of importance to them. This information is intended to help readers gain additional understanding of each of these different languages.

References

  • [ANSI 1989] ANSI C. 1989. ANSI X3.159-1989.
  • [DoD 1978] U.S. Department of Defense. June 1978. ``Department Of Defense Requirements for High Order Computer Programming Languages: "Steelman"'' Electronically available at "http://www.dwheeler.com/steelman".
  • [Ellis 1990] Ellis, Margaret A., and Bjarne Stroustrup. 1990. "The Annotated C++ Reference Manual" (ARM). ISBN 0-201-51459-1 Reading, MA: Addison-Wesley.
  • [FSF 1995] Free Software Foundation. 1995. "Where's the Template?". Using and Porting GNU C. Available at many locations, e.g. "http://www.delorie.com/gnu/docs/gcc/gcc_toc.html".
  • [ISO 1995] ISO. January 1995. Ada 95 Reference Manual. ANSI/ISO/IEC-8652:1995. Available at "http://www.adahome.com/rm95/".
  • [Kernighan 1988] Kernighan, Brian W., and Dennis M. Ritchie. 1988. "The C Programming Language". Second Edition. ISBN 0-13-110362-8. Englewood Cliffs, NJ: Prentice-Hall.
  • [OMG 1995] Object Management Group. July 1995. The Common Object Request Broker: Architecture and Specification. Revision 2.0. Section 15.1.2 says ``Because C++ implementations vary widely in the quality of their support for templates, this mapping does not explicitly require their use ...''.
  • [Seidewitz 1996] Seidewitz, Ed. October 1996. "Another Look at Ada 95". Object Magazine. NY, NY: SIGS Publications Inc.
  • [Stroustrup 1991] Stroustrup, Bjarne. 1991. The C++ Programming Language. Second Edition. ISBN 0-201-53992-6. Reading, MA: Addison-Wesley.
  • [Sutherland 1996] Sutherland, Jeff. September 1996. "Smalltalk Manifesto". Object Magazine. NY, NY: SIGS Publications Inc.

**This paper is not endorsed by, and does not necessarily represent the views of, the Institute for Defense Analyses (IDA), the U.S. Department of Defense (DoD), or the U.S. Government.

I am grateful to Michael Kappel, Magnus Kempe, and James Kuehn for their constructive comments.

Appendix: Table Comparing Four Languages to Steelman

In this table, the left-hand column gives the Steelman requirement. The next four columns show how well Ada, C, C++, and Java meet this requirement. An entry of "yes" indicates that the language and its major implementations generally meet the requirement, while a "no" indicates that requirement is generally not met. There are two intermediate entries: "partial" indicates some of the requirement is met, but a significant portion (or intent) of the requirement is not met, "mostly" indicates that the requirement is generally met, but some specific capability of the requirement is not fully met. Underneath the columns for each language is commentary explaining these entries.

I have tried to be fair to all of these languages. Nevertheless, some of these entries, particularly in section 1, are judgement calls. Readers are encouraged to revisit each entry (particularly in section 1), compare each language, and draw their own conclusions. Items which I felt are particularly questionable have been marked with a question mark ("?").

Requirement Ada C C++ Java

A call to implies the effective copy of memory from one position to another one. Whenever the size of the memory copied is correct, the call will always work.

...and this is exactly what's missing in your first code. The pointer to void, , is a way to point to any variable, whichever its type is. This implies there is no inherent size information when dealing with pointers (because different types have different sizes).

For example:

In this code, carries two informations: the address in which is stored, and that the information there spans for four bytes in a 32 bits system (8 bytes in a 64 bits one), i.e., the result of . Therefore, this will work:

...because the system knows where to store the rvalue (11), and in how many bytes.

So, in order for the first code to work, we should write instead something like (provided the type of the elements of the vector is , and that I understand what does):

Anyway, this won't exactly work if the element of the vector contains pointers to memory in the heap, for example. Well, you'd be copying the pointers, but not the content itself pointed by them. If you don't keep this in mind, you'll probably find yourself with unwanted surprises.

Hope this helps.

answered May 23 '13 at 10:03

Leave a Comment

(0 Comments)

Your email address will not be published. Required fields are marked *