View previous topic :: View next topic |
Author |
Message |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Wed Mar 24, 2010 7:22 am Post subject: Equivalence in Module |
|
|
I have a problem equivalencing character variables of different lengths, where the longer (*1024) is declared in the MODULE, and equivalenced to local character variables C1*1 and C2*2. The error message is not technically correct.
Code: |
[FTN95/Win32 Ver. 5.40.0 Copyright (c) Silverfrost Ltd 1993-2009]
PROCESSING MODULE [<EDIT_PARAMETERS> FTN95/Win32 v5.40.0]
NO ERRORS [<EDIT_PARAMETERS> FTN95/Win32 v5.40.0]
0019) EQUIVALENCE (XCOM,C1), (XCOM,C2)
*** Error 1029: This EQUIVALENCE would cause a redefinition of the USEd
variable XCOM
*** Error 1029: This EQUIVALENCE would cause a redefinition of the USEd
variable XCOM
2 ERRORS [<EXECUT> FTN95/Win32 v5.40.0]
*** Compilation failed
|
If I make the character variable in the module > 1024 (lencom) then the error report goes away ??
Is EQUIVALENCE allowed for modules ?
Could the error test check if the equivalenced variables do not extend the declared length of the character in the module ?
I've cut down the following code to show the problem.
Code: | ! Last change: JDC 24 Mar 2010 2:34 pm
module edit_parameters
!
INTEGER*4, PARAMETER :: milion = 1000000 ! 1 million
INTEGER*4, PARAMETER :: MAXSTR = 750*milion ! max characters in file 750mb
INTEGER*4, PARAMETER :: LENCOM = 1024 ! max characters in command
!
! common variables
!
character*1 CSTOR(MAXSTR) ! text storage array
character (len=lencom) :: XCOM ! command line
end module edit_parameters
SUBROUTINE EXECUT
!
USE edit_parameters
!
CHARACTER C1*1, C2*2
EQUIVALENCE (XCOM,C1), (XCOM,C2)
!
IF (C2 == 'NL'.OR.C2 == 'nl') GOTO 601 ! not locate
IF (C1 == 'N' .OR.C1 == 'n') GOTO 601 ! next line
!
601 return
end
|
|
|
Back to top |
|
 |
IanLambley
Joined: 17 Dec 2006 Posts: 506 Location: Sunderland
|
Posted: Wed Mar 24, 2010 1:09 pm Post subject: |
|
|
What about using:
Code: |
EQUIVALENCE (XCOM(1:1),C1), (XCOM(1:2),C2)
|
is that allowed?
Ian |
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Thu Mar 25, 2010 12:47 am Post subject: |
|
|
Ian,
I thought EQUIVALENCE merely set the memory address of the start of the variables to coincide, although it can be used to redefine the maximum size of a common block.
I did find another error using EQUIVALENCE when converting to a module, where I previously equivalenced an array to a list of variables in a common block. The statement SEQNENCE appears to apply to a TYPE definition, but I don't know if there is any guarantee about the sequence of variables in a module agreeing with their memory order. Indeed, from my reading of the .map, larger variables in a module are stored in a different place in memory.
My error is equivalencing the defined variable in the module to smaller variables. It may be too much to ask and EQUIVALENCE is not allowed.
I did try your suggestion, but it gave the same error message.
John |
|
Back to top |
|
 |
IanLambley
Joined: 17 Dec 2006 Posts: 506 Location: Sunderland
|
|
Back to top |
|
 |
JohnCampbell
Joined: 16 Feb 2006 Posts: 2615 Location: Sydney
|
Posted: Mon Mar 29, 2010 12:10 am Post subject: |
|
|
Ian,
Thanks for that. It appears SEQUENCE is limited to TYPE structures. I don't know of any sequence assumptions that can be applied to a MODULE.
My error relates to the use of C1 and C2 as an easier way of addressing the first 2 characters of a larger character variable XCOM*512. Although in this case, the use of EQUIVALENCE does not require any assumptions of order of variables in the module, the general rule of not being able to assume variable sequencing appears to be applied.
I have a number of coding examples, where I have placed a list of variables in common and then used the first variable as the address and number of bytes in binary read/write routines to simplify the I/O.
I don't think error 1029 should be applied in this case, inless I am missing something else.
John |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Mon Mar 29, 2010 8:24 am Post subject: |
|
|
I will aim to have a look at this problem when I can but I have a back log of things to do at the moment.
It looks like it may be something to do with the way that the memory is allocatied by FTN95. If so then the behaviour may be different with and without /check. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Tue Apr 20, 2010 1:54 pm Post subject: |
|
|
I can see what is happening but I am not yet sure if a fix is needed.
As soon as your module string has length greater than 1024, FTN95 decides to store the string as it would in a COMMON block. This has something to do with good memory usage.
Now the equivalence works OK for a COMMON block hence no failure.
I do not know if MODULE storage allows for equivalence, i.e. does the standard permit this construction? Probably not. If it does then I guess that FTN95 should put smaller strings into COMMON when EQUIVALENCE is used. The problem is that the usage is not known when the module is created.
I hope that this addresses the problem and that you are happy that a fix to the compiler is probably not required. |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Tue Apr 20, 2010 3:15 pm Post subject: |
|
|
Further to my comment above, this usage is not permitted by the Standard and is trapped by FTN95 when using /ISO on the command line.
In effect character variables of length greater than 1024 correspond to an FTN95 extension to the Standard. |
|
Back to top |
|
 |
|