Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Question about substrings

Intel_C_Intel
Employee
865 Views

The documentations states that for a character string of the form

v(e1:e2)

"Both e1 and e2 must be within the range 1,2, ..., len, where len is the length of the parent character string. If e1 exceeds e2, the substring has length zero.

So is it safe to have a substring of length 0? I.e., I have code like:

l=len_trim(string) !where string is all blank

call sub(string(1:L))

where sub is like

subroutine sub(string)

character string*(*)

if (len_trim(string) .gt.0) then

do stuff

endif
end

It works, but can it lead to trouble? Do I have to check for this?

0 Kudos
12 Replies
Intel_C_Intel
Employee
865 Views
I have no idea how this got in here 3 times.. Sorry.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
865 Views

It's [supposed to be *] safe. Of course, you can't do much with such a string, but LEN and LEN_TRIM will return 0 and assignment will be a no-op. I don't have Standard handy, but I suppose you shouldn't try internal WRITE on it.

Jugoslav

*) However, the feature in question looks like a fertile ground for compiler bugs -- I'm not saying there is an actual one in CVF or IVF, just that it looks obscure enough that it can be a good candidate for overlooking.

0 Kudos
Jugoslav_Dujic
Valued Contributor II
865 Views
P.S. You (only you and Steve as administrator) can go back to extra posts and delete them while logged in.
0 Kudos
Steven_L_Intel1
Employee
865 Views
I'm not sure users can delete their own posts. I'll take care of it.
0 Kudos
Steven_L_Intel1
Employee
865 Views
This is legal in Fortran 90. If the end position is less than the start position, the string has zero length. F77 did not allow for this, however, so old compilers may behave erratically with zero-length strings.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
865 Views
I'm not sure users can delete their own posts. I'll take care of it.
They can -- I did it myself several times before (when accidental multiposting occurred). I didn't test if it makes difference when the message is first in the thread.
Jugoslav
0 Kudos
Intel_C_Intel
Employee
865 Views
Thanks; it's a real convenience for me when intrepreting arbitrary (possibly long) format-free user input strings. I don't believe it worked this way in CVF.
I tried to find a way to delete the extras, but couldn't figure out how.
0 Kudos
Steven_L_Intel1
Employee
865 Views
It worked in CVF, as far as I know.
0 Kudos
Jugoslav_Dujic
Valued Contributor II
865 Views

[Doesn't really matter, but for information] "Delete message" option can be found under "Options" "menu" on the blue header of each message. It is active only if it is your message and you're logged in.

Jugoslav

Message Edited by JugoslavDujic on 06-18-2004 10:56 AM

0 Kudos
Intel_C_Intel
Employee
865 Views
Actually, it seems to appear under options only if it's yours AND you are still in the session that created it. Can't come back to it later....
0 Kudos
Jugoslav_Dujic
Valued Contributor II
865 Views

Dunno -- I've just successfully edited myprevious message from this thread, couple of weeks old.

Jugoslav

0 Kudos
Intel_C_Intel
Employee
865 Views
I still can't do it.....
0 Kudos
Reply