- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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
Lien copié
0 Réponses
Répondre
Options du sujet
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable