- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
What does this mean, and how can I avoid it?
character*(*) function gaw(line,separ,number)
implicit none ...
Error: A CHARACTER function name must not be declared with an asterisk type-param-value (i.e., (LEN=*)) if the function is a module function. [GAW]
This works fine in CVF.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A function name shall not be declared with an asterisk type-param-value unless it is of type CHARACTER and is the name of the result of an external function or the name of a dummy function.
A module function is not an external function. The standard is trying to get rid of character(*) functions. Offhand, I can't think of what problem they may cause, but I guess we chose to follow the standard here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Steve,
This seems like a shortcomings of the language. i.e. there is no means for the character function to determine the length of the buffer to which it references. May be cause for buffer overrun.
It would seem like a good way to handle this is to require an interface block for such functionsand to place the "descriptor" (or reference to the descriptor) on the call stack then redefine the function name inside the function with pointer attribute and associate the function name (now pointer to character array) with the hidden argument(descriptor).
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Adams, Brainerd et al "Fortran 95 Handbook" show an example of a function using result to return a character string whose length is set to the length of the function argument, with CONTAINS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For example, you can do this:
function func(arg)
character(*), intent(in) :: arg
character(len(arg)) :: func
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The point was not to have to explicitlypass the length of the buffer referenced by the function. Nor implicitly assume the length of the output buffer is related to the input arg(s).
Assume
character :: buf(6)
real :: PI =3.14159
...
buf = MyFortranFunctionToConvertToString(PI)
The character function should have a goof proof method of obtaining the destination buffer size. Requiring the use of a dummy argument for this purpose is not goof proof.
buf = MyFortranFunctionToConvertToString(PI,size(buff))
Note type-o on line. If you are going to add an argument you might as well use a CALL
Requiring the user to write the conversion function as a CALL (using 2 args) is a bother.
I guess if you want portable code then stick with the worst common denominator...
Now where did I place that FORTRAN-II programmers manual.
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
With CHARACTER(*) functions, the caller must explicitly declare the one and only result length that will be returned when that function is called This is an awkward thing to do and you often don't know at compile-time what that length should be. (If you did, perhaps you should declare the function with a fixed length.
Being able to use a run-time expression for the length is quite liberating. How you determine that length is up to you - most applications do want it to be based on the length of an argument, but you could use a COMMON or module variable too if you liked.
![](/skins/images/895D6060305DF45A57FACF854B5A8CD1/responsive_peak/images/icon_anonymous_message.png)
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page