Silverfrost Forums

Welcome to our forums

cast from .NET System.Int32 to INTEGER*4

7 Jun 2011 12:18 #8357

How can I CAST the Datatype from .NET System.Int32 to INTEGER*4?

Is there any table with casting samples?

Thanks allot Greetings from Germany Michael

7 Jun 2011 9:13 #8359

Quoted from m.burkhardt How can I CAST the Datatype from .NET System.Int32 to INTEGER*4?

Forgive me if I have misunderstood your question. It depends what you mean by CAST since Fortran 95 does not have this concept. The following code works. This is a bit like a dynamic cast in C++. I tried to do a static cast (C and C++) using equivalence but you get a compile time error when you try to equivalence the two variables.

Perhaps there is a .NET utility for doing it; I don't know. Others with more .NET knowledge than I may know some more.

program anon

   object('System.Int32') :: a
   integer*4 :: b

   a = 123

   ! cast a to b at run time using the transfer intrinsic
   b = transfer(a,b)
   print *, b

end program anon
8 Jun 2011 6:35 #8360

Here is the part of a code I mean:

OBJECT('System.Object[]') :: oR
OBJECT('System.Int32') :: nResult
OBJECT('System.String') :: sString
INTEGER*4 VALUE
CHARACTER*10 STR

oR = NEW@('System.Object[],2)

! Get Object and want to Cast to Integer*4
oR(1) = DOTNETGetObjectValue(1)
! CAST ????
VALUE = CAST@(oR(1), INTEGER*4)
VALUE = transfer(???,???)

! Get Object and want to Cast to CHARACTER*6
oR(2) = DOTNETGetObjectValue(2)
! CAST ????
STR = CAST@(oR(2), CHARACTER*6)
STR = transfer(???,???)
21 Jun 2019 5:00 #23824

I am having the same issue, you can work around it simply by not casting from System.Object to a value type, but usually means a bit more code to provide value types un-boxed or their byte representations seem to get messed up...

https://forums.silverfrost.com/Forum/Topic/3578

Please login to reply.