Документ взят из кэша поисковой машины. Адрес
оригинального документа
: http://www.sao.ru/precise/Midas_doc/doc/94NOV/vol1/node42.html
Дата изменения: Fri Feb 23 14:07:43 1996 Дата индексирования: Tue Oct 2 17:21:17 2012 Кодировка: Поисковые слова: jet |
Because keywords are implemented as a global data structure, different MIDAS procedures can access the same keyword. This useful feature can cause problems, however, if these keywords just serve as local, temporary variables like the DO variables. Consider the procedures below:
!+
! Example 11, MIDAS procedure exa11.prg
!+
WRITE/KEYWORD N/I/1/1 0
DO N = 1 10
@@ test
ENDDO
!+
! MIDAS procedure test.prg
!+
WRITE/KEYWORD N/I/1/1 0
DO N = 1 12
WRITE/KEYWORD INPUTI/I/12/1N
![]()
ENDDO
Executing @@ exa11 will give some unexpected results, since both
procedures access the same integer keyword N as a common variable.
Therefore, procedures should use local keywords for DO loops and internal
working storage. Local keywords are defined inside a MIDAS procedure via the
command DEFINE/LOCAL.
They are only known inside the procedure where they are defined (if the
lower_levels_flag is set, they are also defined
in all procedures called from this procedure).
Local keywords may have the same name as an existing global keyword (except the
system keyword names as stored in MID_MONIT:syskeys.dat) or local
keyword of any other procedure, since local keywords are searched
before the global ones.
The above example will work, if modified as follows:
!+
! Example 12, MIDAS procedure exa12.prg
!+
DEFINE/LOCAL N/I/1/1 0
DO N = 1 10
@@ test
ENDDO
!+
! MIDAS procedure test.prg
!+
DEFINE/LOCAL N/I/1/1 0
DO N = 1 12
WRITE/KEYWORD INPUTI/I/12/1N
![]()
ENDDO
Local keywords are deleted when returning to the next higher level at the end of a procedure.