Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29286 Discussions

Question about default inits and equivalence

jeremy_h
New Contributor I
1,075 Views
Hi,

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))
C Also tried EQUIVALENCE (ZESC, ZCURS(1:))

C This works: ZESC = CHAR(27)
[/bash]
There are no doubt better ways of achieving this, but this worked under CVF.

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
0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,075 Views
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'

View solution in original post

0 Kudos
5 Replies
Steven_L_Intel1
Employee
1,076 Views
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'
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,075 Views
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
0 Kudos
Steven_L_Intel1
Employee
1,075 Views
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.
0 Kudos
jeremy_h
New Contributor I
1,075 Views
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
0 Kudos
jimdempseyatthecove
Honored Contributor III
1,075 Views
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
0 Kudos
Reply