- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
In CVF, we used the following declarations to create escaped string sequences:
In IVF (currently using 11.1), the EQUIVALENCE does NOT overwrite the space in ZCURS. Not being a language reference manual guru, I would like to know what Fortran rule allows IVF to either ignore the Equivalence, or perform it out of order.
Regards and thanks - Jeremy
In CVF, we used the following declarations to create escaped string sequences:
[bash] CHARACTER*3 ZCURS /' VK'/ CHARACTER*1 ZESC /27/ EQUIVALENCE (ZESC, ZCURS(1:1))There are no doubt better ways of achieving this, but this worked under CVF.
C Also tried EQUIVALENCE (ZESC, ZCURS(1:))
C This works: ZESC = CHAR(27)
[/bash]
In IVF (currently using 11.1), the EQUIVALENCE does NOT overwrite the space in ZCURS. Not being a language reference manual guru, I would like to know what Fortran rule allows IVF to either ignore the Equivalence, or perform it out of order.
Regards and thanks - Jeremy
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran rule you are violating is "A storage unit shall not be explicitly initialized more than once in a program." Your program is non-standard and the interpretation unspecified.
You could do this:
CHARACTER(1), PARAMETER :: ZESC = CHAR(27)
CHARACTER(3) :: ZCURS = ZESC//'VK'
You could do this:
CHARACTER(1), PARAMETER :: ZESC = CHAR(27)
CHARACTER(3) :: ZCURS = ZESC//'VK'
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The Fortran rule you are violating is "A storage unit shall not be explicitly initialized more than once in a program." Your program is non-standard and the interpretation unspecified.
You could do this:
CHARACTER(1), PARAMETER :: ZESC = CHAR(27)
CHARACTER(3) :: ZCURS = ZESC//'VK'
You could do this:
CHARACTER(1), PARAMETER :: ZESC = CHAR(27)
CHARACTER(3) :: ZCURS = ZESC//'VK'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The question may be: What order is required of data initialization statements with respect to the source code? I have no comment as to what the Fortran specification states to this. If you consider
IF((a .GT. b) .AND. (c .GT. d)) ...
Where either or both get evalued inany order. Then apply this behavior to initializers, then the chicken and egg scenario of which comes first /27/ or ' ' comes in to play.
Consider something along the line of:
CHARACTER*3 ZCURS
CHARACTER*1 ZESC /27/
CHARACTER*2 VK /'VK'/
EQUIVALENCE (ZESC, ZCURS(1:1))
EQUIVALENCE(VK, ZCURS(2:3))
OR:
CHARACTER*3 :: ZCURS= CHAR(27)//'VK'
CHARACTER*1 :: ZESC
EQUIVALENCE (ZESC, ZCURS(1:1))
This will remove any wiggle room the compiler may have to initialize the variables.
Jim Dempsey
IF((a .GT. b) .AND. (c .GT. d)) ...
Where either or both get evalued inany order. Then apply this behavior to initializers, then the chicken and egg scenario of which comes first /27/ or ' ' comes in to play.
Consider something along the line of:
CHARACTER*3 ZCURS
CHARACTER*1 ZESC /27/
CHARACTER*2 VK /'VK'/
EQUIVALENCE (ZESC, ZCURS(1:1))
EQUIVALENCE(VK, ZCURS(2:3))
OR:
CHARACTER*3 :: ZCURS= CHAR(27)//'VK'
CHARACTER*1 :: ZESC
EQUIVALENCE (ZESC, ZCURS(1:1))
This will remove any wiggle room the compiler may have to initialize the variables.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is best to not use EQUIVALENCE for this purpose. The language provides perfectly fine ways of accomplishing the end result without EQUIVALENCE. It may even be that the combined string can be made a PARAMETER.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Excellent answers, I really appreciate Steve's quote from the reference manual, so now we can find other similar errors in the code base.
- Jeremy
- Jeremy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve's recommendation of using the parameter is much better....
Unless ZESC needs to be writable (generally it does not). In your case ZCURS is fully writable, but it too could be a PARAMETER. Pumping escape sequences out to a VT100 (or other device) is likely not a performance issue so using a variable as opposed to literal should not be an issue.
Jim Dempsey
Unless ZESC needs to be writable (generally it does not). In your case ZCURS is fully writable, but it too could be a PARAMETER. Pumping escape sequences out to a VT100 (or other device) is likely not a performance issue so using a variable as opposed to literal should not be an issue.
Jim Dempsey

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