User Tools

Site Tools


casting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
casting [2018/09/04 03:35] wolfgangriedmanncasting [2018/09/07 04:04] (current) wolfgangriedmann
Line 15: Line 15:
 will compile in Vulcan.NET, but not in X#. will compile in Vulcan.NET, but not in X#.
 The first assignment will compile and work in X#, because the compiler knows the type of both variables and inserts a conversion method - so this code is safe. The first assignment will compile and work in X#, because the compiler knows the type of both variables and inserts a conversion method - so this code is safe.
-The second assignment will not compile in X# because it cannot work in a .NET world - it is simply not admitted. A member of the development team stated: ''For this reason, we intentionally disallowed that specific syntax (OBJECT(_CAST, i)) in order to trap some problems in compile time and not at runtime later.''+The second assignment will not compile in X# because it cannot work in a .NET world - it is simply not admitted. A member of the development team stated: ''For this reason, we intentionally disallowed that specific syntax (OBJECT(_CAST, i)) in order to trap some problems in compile time and not at runtime later.'' This refers to the second assignment (with the _cast), but not to the first, as it is legal code.
  
 In VO, sometimes casts are used as follows: In VO, sometimes casts are used as follows:
Line 30: Line 30:
 In .NET such pointers are not allowed, therefore the development team has disallowed the compilation of such code. In .NET such pointers are not allowed, therefore the development team has disallowed the compilation of such code.
 The only valid representation of an object by a numeric variable is when the numeric is an index to an array of objects, and it remains valid also when the garbage collector kicks in. But this type of valid code is rarely seen in VO code. The only valid representation of an object by a numeric variable is when the numeric is an index to an array of objects, and it remains valid also when the garbage collector kicks in. But this type of valid code is rarely seen in VO code.
 +And the .NET Framework has another possibility to map an object to a numeric variable: the System.Runtime.Interopservices.GCHandle structure. Please see this page for more details: [[gchandle|GCHandle: cast an object to a number]]
  
 Please see the entire thread about it in the X# forum: [[https://www.xsharp.info/forum/public-product/832-2-0-0-2-cannot-cast-type-int-to-object|www.xsharp.info/forum/public-product/832-2-0-0-2-cannot-cast-type-int-to-object]], specially the last two messages. Please see the entire thread about it in the X# forum: [[https://www.xsharp.info/forum/public-product/832-2-0-0-2-cannot-cast-type-int-to-object|www.xsharp.info/forum/public-product/832-2-0-0-2-cannot-cast-type-int-to-object]], specially the last two messages.
  
casting.txt · Last modified: 2018/09/07 04:04 by wolfgangriedmann