Posts

Ada 2012 Static Predicates

1.      Subtypes Every Ada type is associated with a subtype. A subtype is a subset of the base type, commonly with some restriction in the set of values valid for the subtype. For instance, Ada provides a pre-defined type named Integer. Integer is a signed type representing all the values in the range of -2**31..2**31 – 1. Ada also provides two pre-defined subtypes of Integer: Natural, which is an integer with a minimum value of 0, and Positive which is an integer with a minimum value of 1. Every instance of Natural or Positive is also an instance of Integer. This capability to define subtypes has been a part of Ada since the first Ada language standard in 1983. While this subtype capability has been very useful, it had some restrictions. Subtype ranges were always restricted to contiguous ranges. For instance, the syntax for defining the Natural subtype mentioned above is: subtype Natural is Integer range 0..Integer’Last;   Integer’Last evaluates to ...

Comparison of Array Based Stacks in C and Ada

Comparison of Array Based Stacks in C and Ada The stack is one of the simplest data structures. Array-based stacks can be implemented in all languages supporting arrays, even including early versions of Fortran which did not support pointers. This comparison is based upon C code published at http://www-cs.ccny.cuny.edu/~peter/dstest.html The C code published at http://www-cs.ccny.cuny.edu/~peter/dstest.html supports the book Advanced Data Structures authored by Peter Braß and published by Cambridge University Press. The Ada code uses Ada2012, which added aspect specifications, pre and post conditions, type invariants and subtype predicates to the Ada language. Descriptions of these and other features added in the Ada 2012 version are available at  The Ada 2012 Rationale Array Stack The C code for Array Stack is shown below. Example 1 ArrayStack.c #include <stdio.h> #include <stdlib.h> typedef int item_t; typedef struct ...