D language type

xiaoxiao2021-03-06  44

Types of

Basic data type

Keyword Description Default initial value (.init) Void None - Bit Single Bit False Byte Signed 8 Bits 0 Ubyte Unsigned 8 Bits 0 Short Signed 16 Bits 0 Ushort Unsigned 16 Bits 0 Int Signed 32 Bits 0 UINT UNSIGNED 32 BITS 0 Long Signed 64 BITS 0L ULONG UNSIGNED 64 BITS 0L CENT SIGNED 128 BITS (for future reservation) 0 ucent unsigned 128 bits (for future reservation) 0 FLOAT 32 BIT floating point FLOAT.NAN DOUBLE 64 BIT floating point Double.Nan Real hardware supported maximum Floating point number (Realize: 80 bits on Intel CPU) Real.Nan ifloat virtual float float.nan * 1.0i idouble Double Double Double.nan * 1.0i IREAL virtual real real.nan * 1.0i cfloat two FLOAT values Multiple float.nan float.nan * 1.0i cdouble plural Double Double Double.Nan Double.nan * 1.0i creAl complex Real real.nan real.nan * 1.0i char unsigned 8 bit UTF-8 0xff Wchar unsigned 16 bit UTF-16 0xffffff Dchar unsigned 32 bit UTF-32 0x0000FFFFFF

Derived data type

Pointer array function

User defines data type

Alias ​​TypeDef enumeration structure combined class

The pointer conversion D allows the pointer to the non-pointer, non-pointer to the conversion of the pointer, but does not do such an operation to the pointer to the data allocated by the garbage collection program.

Implicit conversion d has many types, some are built-in, and others are derived. If each type of conversion requires explicit transformation, it will be very troublesome, so we use implicit conversions to automatically handle those obvious transformations.

The type using the typedef declaration can be converted to the type it represent, but it must be explicitly transformed. E.g:

Typedef int myint;

INT I;

Myint M;

i = m; // ok

m = i; // error

M = CAST (MyInt) i; // ok

Integers increase the type below will be implicit

Int:

Bit

Byte

Ubyte

Short

Ushort

ENUM

charr

Wchar

Dchar

The type using the typedef declaration will be converted to the type it represents.

Common arithmetic conversion common arithmetic conversion converts the operand of the binary operator into a generic type. This operand must already be an arithmetic type. The following rules will be applied in order:

The type using the typedef declaration will be converted to the type it represents. If the operand is REAL, the other operator will be converted to REAL. If an operand is Double, the other operand will be converted to Double. If an operand is float, the other operator will be converted to float. Apply an integer to each operand, then:

If the two operands are the same, there is no need to convert. If both operands are symbols or unsigned, the smaller type will be converted to a larger type. If the type of symbol is larger than the unsigned type, the unsigned type will be converted to a symbolic type. Otherwise, the type of symbol will be converted to an unsigned type. There is no member pointer in delegate D, but supports a more useful concept -

Delegates. The delegate is a gathering of two data: an object reference and a function pointer. When the call function is called, the object reference constructs

This pointer.

The declaration of the delegation is very similar to the function pointer, the difference is the keyword delegate replaces (*), and then follows the flag:

INT function (int) fp; // fp is a pointer to the function

Int delegate (int) DG; // DG is a function of functions

C style declaration function pointer syntax also supported:

int (* fp) (int); // fp is a pointer to the function

Entrustment is initialized as a function pointer:

INT func (int);

FP = & func; // fp pointing FUNC

Class OB

{Int Member (int);

}

OB O;

DG = & o.member; // DG is the member function of Object O

//Member commission

Entrusted cannot be initialized with a static member function or a non-member function.

Entrusted to call with function pointers:

FP (3); // Call FUNC (3)

DG (3); // Call O.MEmber (3)

转载请注明原文地址:https://www.9cbs.com/read-59549.html

New Post(0)