Show/Hide Toolbars

XSharp

The USUAL type in X# is implemented as a .Net structure. It contains a type flag and a value. The value can be one of the following types:

NIL, Long, Date, Float, Array, Object, String, Logic, Codeblock, Symbol, Ptr, Int64, DateTime, Decimal, DateTime

The internal type name for this type is XSharp.__Usual
 

Type

Usual Type Number

NIL

0

Long

1

Date

2

Float

3

Array

5

Object

6

String

7

Logic

8

Codeblock

9

Symbol

10

Ptr

18

Int64

22

DateTime

26

Decimal

27

Currency

28

Binary

29

 

Note that some Usual Type numbers are not included in this table. There are defines in the compiler for these numbers, but they are never stored inside a USUAL.
So you can write UsualType(uValue) == REAL8 but that will NEVER be true.

 
You can assign values of these other types to a USUAL but the values will be converted to a type listed in the first table. For example if you assign a DWORD to a USUAL then the runtime will look at the value of the DWORD and if it is smaller or equal to MAX_LONG then it will store the value as a LONG. Otherwise it will store it as a FLOAT. Please note that although we support the Int64 type the DWORD conversion does not use this to be compatible with VO. Also if you assign a PSZ to a USUAL then it will be stored as a STRING. So the runtime will automatically call Psz2String() to get the string representation.
 

Name

Usual Type Number

Byte

11

Short

12

Word

13

DWord

14

Real4

15

Real8

16

PSZ

17

Usual By Ref

19

UInt64

23

Char

24

Dynamic

25

 

The USUAL type is datatype that can contain any data type. It consists internally of a type flag and a value. This type can store any value.

The compiler treats this type in a special way. The compiler will not warn you when you assign a value of type USUAL to another type, but will automatically generate the necessary conversion operation/

 

USUAL is provided primarily for compatibility with untyped code. It is not recommended for use in new code because the compiler cannot perform any type checking on expressions where one or more operands are USUAL. Any data type errors will only be discovered at runtime.

 

Locals, parameters and fields declared as USUAL also incur considerably more runtime overhead than strongly typed variables.

 

The literal value NIL may be assigned into any storage location typed as USUAL. The value NIL indicates the absence of any other data type or value, and is conceptually equivalent to storing NULL into a reference type. NIL is the default value for a local USUAL variable that has not been initialized.

 

When the left operand of the ':' operator is a USUAL, the compiler will generate a late bound call to the method, field or property specified as the right operand. This call may fail if the value contained in the USUAL at runtime does not have such a member, the member type is incorrect or inaccessible, or if the name evaluates to a method and the number of parameters or their types is incorrect. The /lb compiler option must be enabled in order to use a USUAL as the left operand of the ':' operator, otherwise a compile-time error will be raised.

 

Numeric operations and USUAL variables of mixed types.

When you combine 2 USUAL variables in a numeric operation then the type of the result is derived from the types of operands.
The leading principle has been that we try not to loose decimals.

 

The generic rule is:

When the Left Hand Side is fractional then the result is also fractional of the type of the LHS

When the LHS is NOT fractional and the Right Hand Side (RHS) is fractional then the result is the type of the RHS

When both sides are integral then the result has the type of the largest of the two.

 

 

LHS        

\ RHS

LONG

INT64

FLOAT

CURRENCY

DECIMAL

LONG


LONG

INT64

FLOAT

CURRENCY

DECIMAL

INT64


INT64

INT64

FLOAT

CURRENCY

DECIMAL

FLOAT


FLOAT

FLOAT

FLOAT

FLOAT

FLOAT

CURRENCY


CURRENCY

CURRENCY

CURRENCY

CURRENCY

CURRENCY

DECIMAL


DECIMAL

DECIMAL

DECIMAL

DECIMAL

DECIMAL

 

Implementation

The USUAL type is implemented in the structure  XSharp.__Usual