· Lexical · Modules · Declarations · Types · Properties · Attributes · Pragmas · Expressions · Statements · Arrays · Structs & Unions · Classes · Interfaces · Enums · Functions · Operator Overloading · Templates · Mixins · Contracts · Conditional Compilation · Handling errors · Garbage Collection · Memory Management · Floating Point · Inline Assembler · Interfacing To C · Portability Guide · Embedding D in HTML · Named Character Entities · Application Binary Interface |
TypesBasic Data Types
Derived Data Types
User Defined Types
Pointer ConversionsCasting pointers to non-pointers and vice versa is allowed in D, however, do not do this for any pointers that point to data allocated by the garbage collector.Implicit ConversionsD has a lot of types, both built in and derived. It would be tedious to require casts for every type conversion, so implicit conversions step in to handle the obvious ones automatically.A typedef can be implicitly converted to its underlying type, but going the other way requires an explicit conversion. For example: typedef int myint; int i; myint m; i = m; // OK m = i; // error m = cast(myint)i; // OK Integer PromotionsInteger Promotions are conversions of the following types:
If a typedef or enum has as a base type one of the types in the left column, it is converted to the type in the right column. Usual Arithmetic ConversionsThe usual arithmetic conversions convert operands of binary operators to a common type. The operands must already be of arithmetic types. The following rules are applied in order:
Complex floating point types cannot be implicitly converted to non-complex floating point types.
Imaginary floating point types cannot be implicitly converted to
float, double, or real types. Float, double, or real types
cannot be implicitly converted to imaginary floating
point types.
Delegates are declared similarly to function pointers, except that the keyword delegate takes the place of (*), and the identifier occurs afterwards: int function(int) fp; // fp is pointer to a function int delegate(int) dg; // dg is a delegate to a functionThe C style syntax for declaring pointers to functions is also supported: int (*fp)(int); // fp is pointer to a functionA delegate is initialized analogously to function pointers: int func(int); fp = &func; // fp points to func class OB { int member(int); } OB o; dg = &o.member; // dg is a delegate to object o and // member function memberDelegates cannot be initialized with static member functions or non-member functions. Delegates are called analogously to function pointers: fp(3); // call func(3) dg(3); // call o.member(3) |
Add feedback and comments regarding this page.