Go to the first, previous, next, last section, table of contents.


5.4.8 Summary of Declarations

For C++ type names T and S, the above discussion is summarized in the following table.

Form of Decl.  Sort of x (used as global)  Sort of x^, x' (when x is global)
-------------  --------------------------  ---------------------------------
T x            Obj[T]                      T
const T x      ConstObj[T]                 T
T & x          Obj[T]                      T
const T & x    ConstObj[T]                 T
T & const x    Obj[T]                      T
T * x          Obj[Ptr[Obj[T]]]            Ptr[Obj[T]]
const T * x    Obj[Ptr[ConstObj[T]]]       Ptr[ConstObj[T]]
T * const x    ConstObj[Ptr[Obj[T]]]       Ptr[Obj[T]]
T x[3]         Arr[Obj[T]]                 Arr[T]
const T x[3]   Arr[ConstObj[T]]            Arr[T]
struct STS {
  T t; S s;
  };
STS x;         ConstObj[STS]               STS
const STS x;   ConstObj[Const[STS]]        Const[STS]
union UST {
  S s; T t;
  };
UST x;         Obj[UST]                    UST
const UST x;   ConstObj[Const[UST]]        Const[UST]
int x(int i);  ConstObj[cpp_function]      cpp_function

Note that the use of a state-function such as ' and ^ (see section 6.2.1 State Functions) peels off the outermost Obj or ConstObj generator from the sort. See section 6.2.1 State Functions for an explanation of the shorthands x^ and x' for an array name x. See section 11.7 Array Types for the traits that define array sorts.

When these types are composed, the sort becomes the composite of the sorts given. The only apparent exception is the interaction of const and references. When composing arrays with references and pointers, one has to take the C++ precedence rules into account (e.g., [] has higher precedence than *). The following are a few examples.

Declaration             Sort of x (used as global)
-------------           --------------------------
const int &const x;     ConstObj[int]
const int *const x;     ConstObj[Ptr[ConstObj[int]]]
const int x[3][4];      Arr[Arr[ConstObj[int]]]
int *x[10];             Arr[Obj[Ptr[Obj[int]]]]
int (*x)[10];           Obj[Ptr[Arr[Obj[int]]]]
int *x[10][4];          Arr[Arr[Obj[Ptr[Obj[int]]]]]
int (*x)[10][4];       Obj[Ptr[Arr[Arr[Obj[int]]]]]
int *const x[10];       Arr[ConstObj[Ptr[Obj[int]]]]
int ***x;               Obj[Ptr[Obj[Ptr[Obj[Ptr[Obj[int]]]]]]]
struct Str {
  char *s;
  int len;
  };
Str x;                  ConstObj[Str]
struct IntList {
  int val;
  IntList *next;
  };
IntList x;              ConstObj[IntList]
const IntList x;        ConstObj[Const[IntList]]
const int& x(int a[]);  ConstObj[cpp_function]
int (*x)(int i);        Obj[Ptr[ConstObj[cpp_function]]]
int (* const x)(int i); ConstObj[Ptr[ConstObj[cpp_function]]]
int (*x[10])(int i);    Arr[Obj[Ptr[ConstObj[cpp_function]]]]


Go to the first, previous, next, last section, table of contents.