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
Mitarbeiter
1.140Aufrufe

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 Antworten
Intel_C_Intel
Mitarbeiter
1.140Aufrufe
I have no idea how this got in here 3 times.. Sorry.
Jugoslav_Dujic
Geschätzter Beitragender II
1.140Aufrufe

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.

Jugoslav_Dujic
Geschätzter Beitragender II
1.140Aufrufe
P.S. You (only you and Steve as administrator) can go back to extra posts and delete them while logged in.
Steven_L_Intel1
Mitarbeiter
1.140Aufrufe
I'm not sure users can delete their own posts. I'll take care of it.
Steven_L_Intel1
Mitarbeiter
1.140Aufrufe
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.
Jugoslav_Dujic
Geschätzter Beitragender II
1.140Aufrufe
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
Intel_C_Intel
Mitarbeiter
1.140Aufrufe
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.
Steven_L_Intel1
Mitarbeiter
1.140Aufrufe
It worked in CVF, as far as I know.
Jugoslav_Dujic
Geschätzter Beitragender II
1.140Aufrufe

[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

Intel_C_Intel
Mitarbeiter
1.140Aufrufe
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....
Jugoslav_Dujic
Geschätzter Beitragender II
1.140Aufrufe

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

Jugoslav

Intel_C_Intel
Mitarbeiter
1.140Aufrufe
I still can't do it.....
Antworten