- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
My colleague pointed out to me that the Fortran standard says the following of intent(out):
18 The INTENT (OUT) attribute for a nonpointer dummy argument specifies that it shall be defined
19 before a reference to the dummy argument is made within the procedure and any actual argument that
20 becomes associated with such a dummy argument shall be definable. On invocation of the procedure,
21 such a dummy argument becomes undefined except for components of an object of derived type for
22 which default initialization has been specified.
38 If a nonpointer dummy argument has INTENT (OUT) or INTENT (INOUT), the actual argument shall
39 be definable. If a dummy argument has INTENT (OUT), the corresponding actual argument becomes
40 undefined at the time the association is established, except for components of an object of derived type
41 for which default initialization has been specified.
My colleague's interpretation was that this indicates that the value becomes undefined at entry to the routine and if not assigned a value remais so even in the calling routine.
I have been assuming that if an intent(out) parameter is not assigned a value in a routine, it retains its previous value and ifort seems to work like this. Here's a trivial sample:
[fortran]subroutine nonmoduleroutine( x, setit ) integer, intent(out) :: x logical, intent(in) :: setit if ( setit ) x = 1 end subroutine module intentional contains subroutine moduleroutine( x, setit ) integer, intent(out) :: x logical, intent(in) :: setit if ( setit ) x = 2 end subroutine end module program intent_test use intentional integer :: x x = 0 call nonmoduleroutine( x, .false. ) write ( *, '(I)' ) x call nonmoduleroutine( x, .true. ) write ( *, '(I)' ) x call moduleroutine( x, .false. ) write ( *, '(I)' ) x call moduleroutine( x, .true. ) write ( *, '(I)' ) x end program [/fortran]Which prints
0
1
1
2
as one would expect if the original variable retains its value if the output parameter is not written to.
This leads me to interpret that the standard really means that trying to read a value of an output parameter in the routine recieving the output parameter has an undefined result if the read is done prior to assigning to the said parameter in that routine. However, there is no effect on the recieving variable's value in the calling routine if no assignment is done in the called routine. Am I correct?
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
Ссылка скопирована
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
You should not attempt to interpret the standard based on how non-conforming code behaves. The behavior exhibited by your program may change from compiler to compiler, and may be affected by your specific choice of compiler options, the OS version, etc.
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
I'd like to emphasize that my question was really that does the standard mean that the value of the dummy argument is undefined in the context of the routine conteining the intent(out) or also in the calling procedure after the call?
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом
- Отметить как новое
- Закладка
- Подписаться
- Отключить
- Подписка на RSS-канал
- Выделить
- Печать
- Сообщить о недопустимом содержимом

- Подписка на RSS-канал
- Отметить тему как новую
- Отметить тему как прочитанную
- Выполнить отслеживание данной Тема для текущего пользователя
- Закладка
- Подписаться
- Страница в формате печати