About...
Ada Home
Site Guide
Welcome Tour
Online RM95
Ada FAQs

Follow this link to learn more about advertising here
Advertise and reach thousands of Ada programmers!

Ada Home Floors: Resources | Marketplace | Ammunition Dept. | Discovery Tour | Network

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++.


  1. C++ has default constructors and destructors.
    Ada does not.

  2. C++ requires a custom copy constructor to achieve a deep copy.
    Ada automatically defines deep copy operations for every defined data type.

  3. C++ violates the separation of contract and implementation when inline functions are declared.
    Ada does not.

  4. C++ treats arrays as low-level constructs closely related to pointers.
    Ada does not.

  5. 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.

  6. Ada has built-in tasking.
    C++ does not.

  7. Ada has standardized interfaces to COBOL, FORTRAN and C.
    C++ does not
    (it only offers 'extern "C"').

  8. Ada has fixed decimal arithmetic.
    C++ does not.

  9. C++ uses a preprocessor.
    Ada does not.

  10. Ada has a standard model for separate compilation.
    C++ does not.

  11. Ada has built-in support for the Latin1 character set.
    C++ does not.

  12. 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.

  13. Ada allows subtypes differentiated by value ranges.
    C++ does not.

  14. Ada exceptions are the accepted tool for error communication with a program.
    C++ developers have not generally accepted the use of exceptions.

  15. Ada compilers can choose the most appropriate internal representation of data based upon the range of values allowed for a type.
    C++ compilers cannot.

  16. Ada unsigned integers have modular arithmetic.
    C++ unsigned integers do not.

  17. C++ pointer dereference syntax is complex and difficult.
    Ada access dereference is simple.

  18. 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).

  19. Ada encapsulation is accomplished using the Package.
    C++ encapsulation is accomplished using the Class.

  20. 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).

  21. Ada automatically defines comparison operations for every non-limited defined data type.
    C++ does not.

  22. Ada permits array slicing on one-dimensional arrays.
    C++ does not.

  23. C/C++ header files must not be included more than once for a given compile.
    Ada avoids this problem by not using a preprocessor.

  24. Macros are discouraged in C++.
    Macros are not permitted in Ada.

  25. C/C++ switch statements must be guarded from statement fall-through.
    Ada case statements never allow statement fall-through.

  26. 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.

  27. 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.

  28. 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.

  29. Ada records allow bit-aligned fields.
    C/C++ structs allow only byte, word, or nibble aligned fields.

  30. All arrays in C/C++ can be treated as character arrays.
    Ada arrays are distinct types, and cannot masquerade as one another.

  31. C/C++ has unions.
    Ada does not.

  32. Ada has discriminant types.
    C++ does not.

  33. The master function in every C/C++ program is named "main".
    The master procedure in Ada may have any name.

  34. Ada has procedures and functions.
    C++ has functions
    (a function returning "void" is considered equivalent to a procedure).

  35. 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.

  36. 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.

  37. C++ makes generous use of pointer to void (void *).
    Ada has no equivalent to a void pointer.

  38. 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).

  39. C++ allows friend functions and classes.
    Ada does not.

  40. Ada allows child packages.
    C++ does not.

  41. Ada allows the use of named parameters in function calls and record element assignment.
    C++ does not.

  42. C++ has self-referencing operators such as "+=".
    Ada does not.

  43. C++ has pre- and post- increment and decrement operators.
    Ada does not.

  44. C++ has multiple inheritance.
    Ada does not.

  45. 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.

  46. C++ allows arrays of pointers but forbids arrays of references.
    Ada allows arrays of all data types.

  47. C++ supports only one-dimensional arrays
    (multi-dimensional arrays are emulated on top of one-dimensional arrays).
    Ada provides safe multi-dimensional arrays.

  48. Ada allows nested subprograms.
    C++ does not.

  49. 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.

  50. 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.

  51. Ada has a several predefined string classes.
    C++ does not.

  52. Ada has standard classes for calendar and real time.
    C++ does not.

  53. 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.]

  54. 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;


What did you think of this article?

Very interesting
Interesting
Not interesting
Too long
Just right
Too short
Too detailed
Just right
Not detailed enough
Comments:
Resources | Marketplace | Ammunition | Discovery | Network
About... | Ada Home | Site Guide | Welcome Tour | Tutorials
Book Reviews | RM95 | FAQs | References | Compilers | Tools | Bindings
Bookshop | Job Center | Consultants Index | Vendors
Copyright © by Kempe Software Capital Enterprises (KSCE). All Rights Reserved. Reproduction in whole or in part in any form or medium without express written permission of KSCE is strictly prohibited. Ada Home and Home of the Brave Ada Programmers are trademarks of KSCE. Back to the main entrance of the Ada Home
Ada Home
Improvement makes strait roads; but the crooked roads without improvement are roads of Genius. —William Blake

Page last modified: 1998-02-03