- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I'm porting some code from CVF6.1 to IVF9.0 and have come acrossan issue with initialising variables.CVF would allowyou to specify both an initialisation expression and a data statement for a variable, and run correctly, for example the following code correctly initialises the second element of the array:
PROGRAM INITIALISE
IMPLICIT NONE
INTEGER :: J_ERR
CHARACTER(LEN=64) :: K_COMPONENT (2) = ''
DATA K_COMPONENT (2) /'COMPONENT2'/
J_ERR = 0
END PROGRAM INITIALISE
While IVF will allow the same code to compile, the value of k_componentgets set to ' P T ' when it is examined in the debugger. While having two initialisation expressions like above doesn't seem particularly good programming practice,does anyone know if the above code is actually illegal in F95, and therefore that the compiler should be detecting this?
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
tim@linux:~/src/net> ifort -xB -warn -C shoker.f90
fortcom: Info: shoker.f90, line 7: This variable has not been used. [K_COMPONENT]
CHARACTER(LEN=64) :: K_COMPONENT (2) = ''
---------------------^
fortcom: Info: shoker.f90, line 7: This variable has not been used. [K_COMPONENT]
CHARACTER(LEN=64) :: K_COMPONENT (2) = ''
---------------------^
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
OK, in my actual code I do go on to use k_component, the code above is just meant to illustrate the issue. The following code should compile without any warnings and output the value of the variable which was intended tobe 'COMPONENT2':
PROGRAM INITIALISE
IMPLICIT NONE
CHARACTER(LEN=64) :: K_COMPONENT (2) = ''
CHARACTER(LEN=64) :: K_CMPT
DATA K_COMPONENT (2) /'COMPONENT2'/
K_CMPT = K_COMPONENT(2)
PRINT *, K_CMPT
END PROGRAM INITIALISE
Cheers
R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Initializing a given variable (or element of an array) more than once is not permitted by the standard. Some cases the compiler catches and warns about, some it doesn't. We are aware that the behavior is different from CVF, but the solution is not simple and remains on our task list.
I would recommend against this practice.
I would recommend against this practice.

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