- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My colleague bumped into a baffling case of which I made a short reproduction.
[fortran]program typechecktest integer :: someint someint = ' ' print '(I10)', someint end program [/fortran]The compiler is completely happy with assigning a string to an integer and gives no warnings.
Next I made the string a bit longer, e.g. 'hello'. Now the compiler says:
typechecktest.f90(6): warning #6043: This Hollerith or character constant is too long and cannot be used in the current numeric context. ['hello']
someint = 'hello'
------------^
Looking at the output integer in hex it turns out that the bytes in the integer are assigned the given characters.
What's going on here? Is it legal to assign a string to a variable of type integer? Is there some compiler option that I could use to make the compiler raise an error in these cases?
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is not standard Fortran, but an extension of the Intel Fortran compiler, going back a long time, IIRC.
The reason for the warning is that the string is interpret as a Hollerith constant. As the space where it
is to be stored is only 4 bytes long, the five characters are one character too much.
I suspect that explicitly specifyinga standard like Fortran 90will help detect this sort of things.
Regards,
Arjen
The reason for the warning is that the string is interpret as a Hollerith constant. As the space where it
is to be stored is only 4 bytes long, the five characters are one character too much.
I suspect that explicitly specifyinga standard like Fortran 90will help detect this sort of things.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page