Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Assigning string to integer

Arjen_Markus
Honored Contributor I
663 Views
Hello,

I have run into a peculiar issue:

program char_int
integer :: intvalue
intvalue = '123'
write(*,*) 'Intvalue: ', intvalue
end program

Assigning a literal string value to an integer is accepted (I am using Intel Fortran 11.1 here
on Windows). Assigning a string variable to an integer is not.

Is this a bug or is it an extension specific to Intel Fortran? (I suspect the latter as
/stand:f90 etc do flag it as an error)

Regards,

Arjen

0 Kudos
4 Replies
mecej4
Honored Contributor III
663 Views
It is a rather common extension to the standard, accepted by many compilers. If you are going to use this extension, you may wish to see how the string, which is only 3-bytes long, is padded out to 4 bytes before assignment to the integer variable.
0 Kudos
Arjen_Markus
Honored Contributor I
663 Views
Well, I rather want to avoid that this extension causes problems ;). We changed the type of one variable
in our program from a character string to an integer and later I noticed that some character comparisons
and assignments were left. Using the /stand:f03 option catches them though.

Regards,

Arjen
0 Kudos
Steven_L_Intel1
Employee
663 Views
This is indeed an extension and is part of support for Fortran 66 Hollerith constants. In Fortran 66 you could do:

intvalue = 3H123

and many compilers allowed '123' as an alternative. We still support this. Note that intvalue does NOT get the integer value 123 in this case!
0 Kudos
Arjen_Markus
Honored Contributor I
663 Views
No, I have seen the value - something very large :). I have had to use Hollerith constants, butthat was
a long, long time ago, when I first encountered Fortran ... Never had to deal with them since.

Thanks for the information,

Arjen
0 Kudos
Reply