replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Possible bug with function that returns a pointer.
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 

Possible bug with function that returns a pointer.

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



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Apr 06, 2012 9:38 pm    Post subject: Possible bug with function that returns a pointer. Reply with quote

The following code contains a function list() that returns a pointer to an array of 10 real values containing 1.0, 2.0, ..., 10.0.

Unfortunately, I get an access violation error when I try and run it. It works fine with my other compilers, It is standard Fortran 90.

I do have a workaround by creating a local array and pointing the function result to that before the function returns, then it works ok.

Best regards,
David.


Code:

module foo
contains
   function list() result(list_vals)
      real, pointer :: list_vals(:)
      integer :: i
      allocate(list_vals(10))
      do i=1, 10
         list_vals(i) = real(i)
      end do
   end function list
end module foo

program anon
   use foo
   real, pointer :: a(:)
   integer :: i
   
   ! Get the list
   a => list()
   
   ! Print the list
   do i=1, 10
      print *, a(i)
   end do
   
   ! Remove list from the heap
   deallocate(a)
end

_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Sat Apr 07, 2012 5:16 pm    Post subject: Reply with quote

I have logged this as a bug to be investigated.
Back to top
View user's profile Send private message AIM Address
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