The -vo7 option directs the compiler to allow implicit casts and conversions that are allowed in Visual Objects but which would normally be illegal or require an explicit cast in X#.
-vo7[+|-]
+ | - | Specifying +, or just -vo7, directs the compiler to allow certain implicit casts and conversions that are allowed in Visual Objects. |
Visual Objects allows implicit casts between types with different semantics, whereas X# normally requires explicit casts in such cases.
For example, Visual Objects allows implicit conversions between integer types and pointer types. While pointers are integers, they have different semantics. Integers are numerical values and pointers are addresses representing memory locations. In addition to the difference in semantics, the size of a pointer is dependent upon the underlying platform whereas the size of an integer does not change from platform to platform (with the exception of System.IntPtr).
While is it possible (and often necessary) to cast between types with different semantics, it should always be done via an explicit cast. This not only insures that the correct conversion code is generated (if necessary), it also self-documents the fact that you are casting one type to another type that has a different meaning.
X# supports most of the casts that Visual Objects supports, but in cases where the types have different semantics, an explicit cast is usually required. However, this can cause a large number of compiler errors in existing Visual Objects code.
Using -vo7 allows the following conversions to be performed implicitly, allowing existing Visual Objects code to compile:
From |
To |
Operation Performed |
PTR |
strongly typed PTR (e.g. INT PTR) |
None, the types are binary compatible. However, the code may fail at runtime if the data the pointer points to is not the correct type. |
INT or DWORD |
strongly typed PTR (e.g. INT PTR) |
None, the types are binary compatible. However, the code may fail at runtime if the data the pointer points to is not the correct type. Note that this conversion is only allowed when the target platform is set to x86. |
INT64 or UINT64 |
strongly typed PTR (e.g. INT PTR) |
None, the types are binary compatible. However, the code may fail at runtime if the data the pointer points to is not the correct type. Note that this conversion is only allowed when the target platform is set to x64 or Itanium. |
OBJECT |
any other reference type |
Compiler inserts an explicit cast to the target type, which may fail at runtime. |
type PTR |
REF type |
The compiler converts the pointer into a reference. Note that even with -vo7, not all pointers can be converted to references or else it would compromise the integrity of the garbage collector. |
1.Open the project's Properties page.
2.Click the Dialect tab.
3.Change the value.
4.Click here to see the property page
The following code is valid in Visual Objects, but will not compile in X# unless -vo7 is used, because CreateObject() returns OBJECT and there is no implicit conversion from OBJECT to a more derived type (such a conversion cannot be guaranteed to be safe, and implicit conversions are always safe).
CLASS foo
...
END CLASS
FUNCTION Start() AS VOID
LOCAL f AS foo
LOCAL s AS SYMBOL
s := #foo
f := CreateObject( s ) // no implicit conversion from 'OBJECT' to 'foo'
RETURN
Using -vo7 has the same effect as if the assignment into f were rewritten as:
f := (foo) CreateObject( s )
In either case, the resulting code is exactly the same, and the cast to foo may fail at runtime. However, the explicit cast self-documents that you expect the return from CreateObject() to contain an instance of foo.
The following example is also valid in Visual Objects, but will not compile in X# unless -vo7 is used, because the @ operator returns the address of its operand (a typed pointer) and pointers are not the same as references in X#:
LOCAL x AS INT
ByRef( @x )
...
FUNCTION ByRef( i REF INT ) AS VOID
i := 5
RETURN
The -vo7 option will automatically convert @x, which resolves to type INT PTR, into REF INT which is compatible with the function parameter. However, it is recommended that you remove the @ operator rather than use -vo7 for this purpose.