[Home]
[Search]
[D]
AggregateDeclaration:
Tag { DeclDefs }
Tag Identifier { DeclDefs }
Tag Identifier ;
Tag:
struct
union
They work like they do in C, with the following exceptions:
struct ABC x;are not allowed, replace with:
ABC x;
struct X { int a; int b; int c; int d = 7;}
static X x = { a:1, b:2}; // c is set to 0, d to 7
static X z = { c:4, b:5, a:2 , d:5}; // z.a = 2, z.b = 5, z.c = 4, d = 5
union U { int a; double b; }
static U u = { b : 5.0 }; // u.b = 5.0
Other members of the union that overlay the initializer,
but occupy more storage, have
the extra storage initialized to zero.
EnumDeclaration:
enum identifier { EnumMembers }
enum { EnumMembers }
enum identifier ;
EnumMembers:
EnumMember
EnumMember ,
EnumMember , EnumMembers
EnumMember:
Identifier
Identifier = Expression
Enums replace the usual C use of #define macros to define
constants. Enums can be either anonymous, in which case they simply
define integral constants, or they can be named, in which case they
introduce a new type.
enum { A, B, C } // anonymous enum
Defines the constants A=0, B=1, C=2 in a manner equivalent to:
const int A = 0; const int B = 1; const int C = 2;Whereas:
enum X { A, B, C } // named enum
Define a new type X which has values X.A=0, X.B=1, X.C=2
Named enum members can be implicitly cast to integral types, but integral types cannot be implicitly cast to an enum type.
Enums must have at least one member.
If an Expression is supplied for an enum member, the value of the member is set to the result of the Expression. The Expression must be resolvable at compile time. Subsequent enum members with no Expression are set to the value of the previous member plus one:
enum { A, B = 5+7, C, D = 8, E }
Sets A=0, B=12, C=13, D=8, and E=9.
.min Smallest value of enum .max Largest value of enum .size Size of storage for an enumerated value For example: X.min is X.A X.max is X.C X.size is same as int.size
enum X { A=3, B, C }
X x; // x is initialized to 3