Show/Hide Toolbars

XSharp

The -vo4 option directs the compiler to implicitly convert numeric types from larger types to smaller types but also from fractional types to integral types.

Syntax

-vo4[+|-]

Arguments

+ | - Specifying +, or just -vo4, directs the compiler to implicitly convert signed integer values to/from unsigned values, and larger integer types to smaller integer types. This provides compatibility with Visual Objects, which permits such conversions without an explicit cast or conversion operator.

Remarks

For safety reasons, this option is off by default. Implicitly converting between signed and unsigned integer types or between larger to smaller integer types can cause numeric overflow errors at runtime or unintended values to be passed depending upon whether overflow checking is enabled or disabled. By default, you must explicitly cast a signed integer to its unsigned counterpart and from larger integer types to smaller integer types and by explicitly doing so, it is assumed that the conversion is known by the programmer to be safe.

 

When this option is enabled, the compiler will implicitly convert the data types listed in the table below:

 

From

To

SByte

BYTE, WORD, Char, DWORD

SHORT

BYTE, SByte, WORD, Char, DWORD

INT

BYTE, SByte, WORD, SHORT, Char, DWORD

INT64

BYTE, SByte, WORD, SHORT, Char, INT, DWORD, UINT64

BYTE

SByte

WORD

SByte, BYTE, SHORT, Char, INT

DWORD

SByte, BYTE, WORD, SHORT, INT

UINT64

SByte, BYTE, WORD, SHORT, Char, INT, DWORD, INT64

REAL8, REAL4, DECIMAL

All other numeric types

FLOAT, CURRENCY

All other numeric types

 

For each conversion, the compiler will raise an appropriate warning. You may disable the warning with The -wx switch, or insert an explicit cast in the source code to eliminate the warning.

 

It is strongly recommended that you do not use this compiler option in new code. All of the conversions listed in the table above have the ability to lose data or return incorrect values, since the range of values in the source data type cannot be represented in the target data type.

 

For example, an INT containing a negative number cannot be represented in a DWORD. Similarly, an INT greater than 65535 cannot be represeneted in a SHORT. If you must mix signed and unsigned types or pass a larger type to a smaller type, you should always supply an explicit cast rather than using -vo4. This will document the fact that the conversion is known to be safe, and it will not suppress compile time errors if incompatible integer types are unintentionally used.

To set this compiler option in the Visual Studio development environment:

 

1.Open the project's Properties page.

2.Click the Dialect tab.

3.Change the value.

4.Click here to see the property page

Example

FUNCTION Start() AS VOID
LOCAL dw := 4294967296 AS DWORD
LOCAL i := -1 AS INT
 
DWORD_Function( i ) // no error if compiled with /vo4
INT_Function( dw ) // no error if compiled with /vo4
RETURN
 
FUNCTION DWORD_Function( x AS DWORD ) AS VOID
? x
RETURN
 
FUNCTION INT_Function( x AS INT ) AS VOID
? x
RETURN