- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm trying to ressurect (eventually convert to F90) some working F77 legacy code and stumbled onto somether strange.
NUM is implicitely an integer array. As such,
1) Forgetting for a minute the last element in he series ('-'), why wouldn't the DATA statement be:
DATA NUM /0, 1, 2, 3, 4, 5, 6, 7, 8, 9/
2) How can an INTEGER be assigned a charcter value (i.e., '-')?
[bash]DIMENSION NUM(11) DATA NUM/'0','1','2','3','4','5','6','7','8','9','-'/[/bash]
NUM is implicitely an integer array. As such,
1) Forgetting for a minute the last element in he series ('-'), why wouldn't the DATA statement be:
DATA NUM /0, 1, 2, 3, 4, 5, 6, 7, 8, 9/
2) How can an INTEGER be assigned a charcter value (i.e., '-')?
Link Copied
6 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do not provide an explicit declaration for NUM, which could easily be a CHARACTER*1 array, --or--
the compiler was a bit sloppy, and the lsb of each integer element of NUM was assigned the byte value of the corresponding character literal in the DATA statement.
Back in the (16-bit) day, MS, DVF and CVF allowed any combination of byte-value overlaying on integer data, sort of an implicit EQUIVALENCE, did no harm as long as the programmer kept track of what was going on.
the compiler was a bit sloppy, and the lsb of each integer element of NUM was assigned the byte value of the corresponding character literal in the DATA statement.
Back in the (16-bit) day, MS, DVF and CVF allowed any combination of byte-value overlaying on integer data, sort of an implicit EQUIVALENCE, did no harm as long as the programmer kept track of what was going on.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
DVF/CVF were never 16-bit.
Actually, what this code depends on is a Fortran 66 extension related to Hollerith constants. Quoted character strings up to four characters could be treated as numeric in certain contexts as an alternative to the Hollerith "H" syntax. We still support this - the manual says:
"If a character constant appears in a numeric context (such as an expression on the right side of an arithmetic assignment statement), it is considered a Hollerith constant."
Actually, what this code depends on is a Fortran 66 extension related to Hollerith constants. Quoted character strings up to four characters could be treated as numeric in certain contexts as an alternative to the Hollerith "H" syntax. We still support this - the manual says:
"If a character constant appears in a numeric context (such as an expression on the right side of an arithmetic assignment statement), it is considered a Hollerith constant."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Allowing a Hollerith constant to be written with ' ' was non-standard, but an extension supported by the most important f66 compilers, and carried over afterwards, even though Hollerith was obsoleted immediately by f77. Not until f90 was there any requirement to support a compile option which would flag it as non-standard.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
IVF help for DATA has the last bullet (in color that means extension) has:
For whatever it is worth: I find that one get different results for NUM when using XLFortran and IVF. For example, NUM(1) is 538976304 with IVF and 807411744. Both compiler do give a warning when enabled. For IVF, with swtich /stand:f03, one gets -- "warning #7550: Fortran 2003 does not allow this data initialization. ['0']".
Abhi
-
If the constant is a Hollerith or character constant, and the variable is a numeric variable or numeric array element, the number of characters that can be assigned depends on the data type of the data item.
If the Hollerith or character constant contains fewer characters than the capacity of the variable or array element, the constant is extended on the right with blank characters. If the constant contains more characters than can be stored, the constant is truncated on the right.
For whatever it is worth: I find that one get different results for NUM when using XLFortran and IVF. For example, NUM(1) is 538976304 with IVF and 807411744. Both compiler do give a warning when enabled. For IVF, with swtich /stand:f03, one gets -- "warning #7550: Fortran 2003 does not allow this data initialization. ['0']".
Abhi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All responses are interesting - thanks. In staring more at this code section, I'm given to believe that NUM is, in fact, a CHARACTER array (as the DATA statement clearly implies). What's strange to me is that nowhere is it declared as CHARACTER. Therefore my guess that it was INTEGER (by virtue of its name in the implicit world of F77: I,J,K,L,M,N).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is INTEGER - but depending on how it's used, it may display as character (with an A format, for example.)
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