- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Are there any problems caused by the following string statement:
character(len=8) :: shortstring
character(len=255) :: longstring
longstring = 'This string is longer than 8 characters'
shortstring = longstring
There are no compiler warnings or run time array bounds tripping even though these are enabled.
I have a program that behaves in a strange way where a user defined variablethat should never be changed (once initialised)is being altered during the run in release mode, though not in debug mode. The behavior suggests a memory overwrite somewhere and I am trying to rule out all possible causes.
Same problem occurs in 11.1.070 & 11.1.067 versions.
Any other suggestions (re optimisation switches to try etc.) would be most welcome.
character(len=8) :: shortstring
character(len=255) :: longstring
longstring = 'This string is longer than 8 characters'
shortstring = longstring
There are no compiler warnings or run time array bounds tripping even though these are enabled.
I have a program that behaves in a strange way where a user defined variablethat should never be changed (once initialised)is being altered during the run in release mode, though not in debug mode. The behavior suggests a memory overwrite somewhere and I am trying to rule out all possible causes.
Same problem occurs in 11.1.070 & 11.1.067 versions.
Any other suggestions (re optimisation switches to try etc.) would be most welcome.
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fortan is very robust against that sort of things. If the string on the right hand side is too long, then
it will be simply be truncated. My guess is that the problem you see is a consequence of another problem.
Do you have a small but complete program in which the error occurs? That would help reproducing it.
Regards,
Arjen
it will be simply be truncated. My guess is that the problem you see is a consequence of another problem.
Do you have a small but complete program in which the error occurs? That would help reproducing it.
Regards,
Arjen
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess there is neithera compiler warning nor a run-time error. Look at Metcalf c.s. Fortran95/2003 pag. 41 where it is explained that your shortstring variabele gets the value 'This str' (without ' of course).
Robert
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
There are no compiler warnings or run time array bounds tripping even though these are enabled
There are no arrays in this context, and the rules of Fortran are quite explicit in covering the assignment of a scalar string expression to a scalar string variable: padding with blanks if the variable is longer than the expression, truncation if shorter.
One is led to conclude that the source of the perceived error (clobbering of a set-once variable) lies elsewhere.
There are no arrays in this context, and the rules of Fortran are quite explicit in covering the assignment of a scalar string expression to a scalar string variable: padding with blanks if the variable is longer than the expression, truncation if shorter.
One is led to conclude that the source of the perceived error (clobbering of a set-once variable) lies elsewhere.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
All the replies are correct - there are no warnings or error messages for behavior strictly defined by the standard. Indeed, many applications depend on this behavior.
It can surprise some people when they do things like:
character(80) string
...
string = 'abcdef'
string = string // 'ghijkl'
and the second assignment has no effect.
It can surprise some people when they do things like:
character(80) string
...
string = 'abcdef'
string = string // 'ghijkl'
and the second assignment has no effect.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi DannyCat
For your memory stomp issue perhaps the following may help:
Use a debug build with optimizations on. Keep the run-time check flags such as /check:bounds etc. as well. May be just use /check:all.
You may not get the exact location of stomp but there is a chance that you will get some useful information. Also try a setting up "data-breakpoint" for the variable in the optimized + debug + check mode.
Abhi
For your memory stomp issue perhaps the following may help:
Use a debug build with optimizations on. Keep the run-time check flags such as /check:bounds etc. as well. May be just use /check:all.
You may not get the exact location of stomp but there is a chance that you will get some useful information. Also try a setting up "data-breakpoint" for the variable in the optimized + debug + check mode.
Abhi

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page