replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Automatic CHARACTER storage; unexpected behaviour
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Automatic CHARACTER storage; unexpected behaviour

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support
View previous topic :: View next topic  
Author Message
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Thu Aug 26, 2010 5:22 pm    Post subject: Automatic CHARACTER storage; unexpected behaviour Reply with quote

Please can someone have a look at this little program and tell me whether it is me or FTN95 that is being very stupid?

Step into the subroutine and observe carefully. The automatic character variable charac does not get assigned, character by character, to char (0). Instead, as soon as the assignment statement is hit for the first time, characters 5 to 10 of charac get set to something different, and charac does not change for the rest of the loop. When the end of the subroutine is reached, charac reverts to what it was on entry.

I can't see anything wrong with the code, but equally I can't believe that a compiler bug this blatant would have escaped detection Shocked

Code:
        program deferred
        integer size
        size = 4
        call sub (size)
        end program deferred
        subroutine sub (n)
        integer i, n
        character (len = n) :: charac
        do i = 1, n
          charac (i: i) = char (0)
        end do
        end subroutine sub
Back to top
View user's profile Send private message Send e-mail
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Thu Aug 26, 2010 6:25 pm    Post subject: Reply with quote

I think that it is just the debugger that cannot cope...

Code:
        program deferred
        integer size
        size = 4
        call sub (size)
        end program deferred
        subroutine sub (n)
        integer i, n
        character (len = n) :: charac
        do i = 1, n
          charac (i: i) = char(i-1)
        end do
        do i = 1, n
          print*, ichar(charac(i:i))
        end do
        end subroutine sub
Back to top
View user's profile Send private message AIM Address
sparge



Joined: 11 Apr 2005
Posts: 371

PostPosted: Fri Aug 27, 2010 12:58 am    Post subject: Reply with quote

Hmmm. ... yes, it looks that way, with your print modification. But what's not to cope with? It must count as a debugger bug, surely.
I see now in my original post, I talked about characters 5 to 10 getting changed when the loop is entered, when charac is only 4 characters long. That's because originally I had size = 10, and cut it down to abbreviate the stepping through in sdbg, but didn't amend the message. That behaviour is obviously system dependent. Here at home, if I set size back to 10, it's only characters 5-8 of charac that change, and what they change to is the value of n. At work, it was the value of i that they changed to (I could see it incrementing as I stepped through the loop).

So sdbg seems to be displaying data at some spurious address. It actually displays the same data whether I ask for memory dump at variable, or memory dump using contents. The address of the data that sdbg displays for charac is nearly the same as the data that is occupying that address, but not the same. On this machine, the address of the data displayed is 0x0360fcd8 and the data displayed is 0x0360fbb8. So I ought to get two different displays depending which flavour of memory dump I ask for, but I don't.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> Support All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group