Ada Home
March 4, 1997
Article
Comparison of Ada and C++ Features
by Jim Rogers, Team Ada member
JimMaureenRogers@worldnet.att.net
Here is a modest list I have compiled which points out
differences between Ada and C++.
-
C++ has default constructors and destructors.
Ada does not.
-
C++ requires a custom copy constructor to achieve a deep copy.
Ada automatically defines deep copy operations for every defined data type.
-
C++ violates the separation of contract and implementation when inline functions are declared.
Ada does not.
-
C++ treats arrays as low-level constructs closely related to pointers.
Ada does not.
-
Ada compilers are capable of strong type checking of all actual parameters applied during the instantiation of a generic.
C++ compilers are incapable of such strong type checking for the instantiation of a template.
-
Ada has built-in tasking.
C++ does not.
-
Ada has standardized interfaces to COBOL, FORTRAN and C.
C++ does not
(it only offers 'extern "C"').
-
Ada has fixed decimal arithmetic.
C++ does not.
-
C++ uses a preprocessor.
Ada does not.
-
Ada has a standard model for separate compilation.
C++ does not.
-
Ada has built-in support for the Latin1 character set.
C++ does not.
-
Ada allows multiple enumeration types to have identical values
(for instance "Mars" can be both the name of a God and the name of a Planet, and the compiler will not let the programmer mix gods and planets).
C++ does not.
-
Ada allows subtypes differentiated by value ranges.
C++ does not.
-
Ada exceptions are the accepted tool for error communication with a program.
C++ developers have not generally accepted the use of exceptions.
-
Ada compilers can choose the most appropriate internal representation of data based upon the range of values allowed for a type.
C++ compilers cannot.
-
Ada unsigned integers have modular arithmetic.
C++ unsigned integers do not.
-
C++ pointer dereference syntax is complex and difficult.
Ada access dereference is simple.
-
Ada formal parameters have modes of "IN", "OUT" and "IN OUT".
C++ has no direct equivalent
(passing a pointer or address is NOT the same as specifying an "IN OUT" parameter mode).
-
Ada encapsulation is accomplished using the Package.
C++ encapsulation is accomplished using the Class.
-
All C++ operators may be overridden.
The Ada assignment operator cannot be overridden
(but the effect of the assignment operation can be redefined for controlled types).
-
Ada automatically defines comparison operations for every non-limited defined data type.
C++ does not.
-
Ada permits array slicing on one-dimensional arrays.
C++ does not.
-
C/C++ header files must not be included more than once for a given compile.
Ada avoids this problem by not using a preprocessor.
-
Macros are discouraged in C++.
Macros are not permitted in Ada.
-
C/C++ switch statements must be guarded from statement fall-through.
Ada case statements never allow statement fall-through.
-
C/C++ switch statements cannot be checked by C/C++ compilers to determine that every possible value for a type has been handled.
Ada case statements are always checked by the compiler to determine that all possible values for the type have been handled.
-
Ada I/O procedures raise exceptions when handling data outside the defined range for the type being input or output.
C++ I/O procedures cannot check for valid values, unless customized by the programmer.
-
Ada integer I/O routines can deal with data in any base from 2 through 16.
C/C++ I/O routines can only deal with data in base 8, 10, or 16.
-
Ada records allow bit-aligned fields.
C/C++ structs allow only byte, word, or nibble aligned fields.
-
All arrays in C/C++ can be treated as character arrays.
Ada arrays are distinct types, and cannot masquerade as one another.
-
C/C++ has unions.
Ada does not.
-
Ada has discriminant types.
C++ does not.
-
The master function in every C/C++ program is named "main".
The master procedure in Ada may have any name.
-
Ada has procedures and functions.
C++ has functions
(a function returning "void" is considered equivalent to a procedure).
-
The default constructor in C++ is often used to supply a set of default values to a class.
Ada records can be defined with default values, which will be used when variable of that type is declared or allocated.
-
C++ array indices always start at 0.
Ada array indices may start at any value, so long as the index type is an integer or enumerated type.
-
C++ makes generous use of pointer to void (void *).
Ada has no equivalent to a void pointer.
-
C++ allows variables to be declared anywhere in a source file, including in the initialization section of a "for" loop.
Ada allows variables to be declared only before the "begin" statement for a block
(note: a loop parameter declares a read-only object (evolving in value) for the duration of a loop).
-
C++ allows friend functions and classes.
Ada does not.
-
Ada allows child packages.
C++ does not.
-
Ada allows the use of named parameters in function calls and record element assignment.
C++ does not.
-
C++ has self-referencing operators such as "+=".
Ada does not.
-
C++ has pre- and post- increment and decrement operators.
Ada does not.
-
C++ has multiple inheritance.
Ada does not.
-
C++ has reference types.
Ada does not. Ada has parameter modes IN, OUT and IN OUT, and access types, which provide all the functionality of C++ reference types.
-
C++ allows arrays of pointers but forbids arrays of references.
Ada allows arrays of all data types.
-
C++ supports only one-dimensional arrays
(multi-dimensional arrays are emulated on top of one-dimensional arrays).
Ada provides safe multi-dimensional arrays.
-
Ada allows nested subprograms.
C++ does not.
-
Declaration of a block statement after an "if" or loop construct is optional in C++.
Ada requires the equivalent of a block statement for all "if" and loop constructs.
-
Ada requires the statement/name of a block to be used at the end of every block. This includes "if", loop, and block statements, as well as subprogram blocks.
C++ has no way to identify the name of a block at the close of the block, except by using comments.
-
Ada has a several predefined string classes.
C++ does not.
-
Ada has standard classes for calendar and real time.
C++ does not.
-
Ada has a completed international standard.
[The Ada 95 revision was approved in early 1995.]
C++ does not.
[January 1998 Note: A C++ standard has been agreed on as of December 1997.]
-
C++ has assertions.
Ada does not.
Comparison of Hello World programs
C++ Version
//Hello World
#include <iostream.h>
int main (void)
{
cout << "Hello World" << endl;
return 0;
}
|
|
Ada Version
-- Hello World
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello is
begin
Put_Line ("Hello World");
end Hello;
|
|
Page last modified: 1998-02-03