- 신규로 표시
- 북마크
- 구독
- 소거
- RSS 피드 구독
- 강조
- 인쇄
- 부적절한 컨텐트 신고
For interaction with which language?
Seriously, CHARACTER*(*) means that any memory associated with STR_OUT is allocated in the caller and info about amount in that memory is passed to Fortran. So, you can't return string of variable length in Fortran as you couldn't in any language because it isn't your routine that takes care about the memory. What you can do is to write something into that buffer whatever the size is.
On the other hand, if you mean "how not to expect length argument from the caller", it is possible:
But note that this means "I expect this buffer not to be smaller than 100". If it actually was, you might easily overwrite "caller's" memory and do some nasty thing.
Note that, for example, almost all Win32 API functions which fill in some string always have an additional length argument which the caller should fill in (e.g. RegQueryValueEx) (although strings are always passed by reference there); that ensures that an error will be returned if the buffer is too small, not that a silent overwrite would occur gobbling the memory.
Jugoslav
Seriously, CHARACTER*(*) means that any memory associated with STR_OUT is allocated in the caller and info about amount in that memory is passed to Fortran. So, you can't return string of variable length in Fortran as you couldn't in any language because it isn't your routine that takes care about the memory. What you can do is to write something into that buffer whatever the size is.
On the other hand, if you mean "how not to expect length argument from the caller", it is possible:
SUBROUTINE FSub(str_out) !DEC$ATTRIBUTES REFERENCE:: str_out CHARACTER(100):: str_out
But note that this means "I expect this buffer not to be smaller than 100". If it actually was, you might easily overwrite "caller's" memory and do some nasty thing.
Note that, for example, almost all Win32 API functions which fill in some string always have an additional length argument which the caller should fill in (e.g. RegQueryValueEx) (although strings are always passed by reference there); that ensures that an error will be returned if the buffer is too small, not that a silent overwrite would occur gobbling the memory.
Jugoslav
링크가 복사됨
0 응답