Silverfrost Forums

Welcome to our forums

Can't ass uint to fortran integer

6 Jul 2011 3:28 #8519

Hello,

Im faced with this problem, You cannot assign an expression of type OBJECT('System.UInt32') to a variable of type INTEGER(KIND=3)

Is there any way to handle a uint in FORTRAN code?

Thanks, Alex.

7 Jul 2011 9:19 (Edited: 12 Jul 2011 5:39) #8529

You can use transfer provided the uint fits in a 32 bit unsigned integer, if not you can use a combination of transfer and iand and a 64 bit integer.

program anon

   object('System.UInt32') a
   integer b, c
   
   b = 12

   ! Just check size is 4 bytes
   print *, 'Number of bytes in a = ', size(transfer(a,(/'A'/)))
   
   ! Assign b to a, i.e. a=b
   a = transfer(b,a)
   
   ! Assign a to c, i.e. c = a
   c = transfer(a, c)

   print *, 'c = ', c

 end
7 Jul 2011 11:02 #8531

Thank you, Ill give that a whirl.

Please login to reply.