replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Assumed size array of derived type + default initialization
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 

Assumed size array of derived type + default initialization

 
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: Mon Oct 07, 2013 4:02 pm    Post subject: Assumed size array of derived type + default initialization Reply with quote

The compiler should generate an ERROR for the following code.

Since type foo_t contains some default initialization (a=1) it is not legal for an array of these to be associated with a dummy argument which is of assumed size and has intent out (assumed shape and intent out would be ok, as would assumed size when there is no default initialization).

Since the size of the dummy array is not known, the compiler cannot therefore carry out the required initialization when proc is called.

Regards
David.

Code:

program anon

   implicit none
   
   type foo_t
      integer :: a = 1
      integer :: b
   end type foo_t

   type (foo_t), dimension(4) :: foo
   integer :: i
   
   foo%a = 0
   
   call proc(foo, 4)

   do i=1, 4
      print *, foo(i)%a, foo(i)%b, ' <-- should print 1, 2'
   end do

contains

   subroutine proc(foo, m)
      integer, intent(in) :: m
      type (foo_t), intent(out) :: foo(*)
      integer i
      do i=1, m
         foo(i)%b = 2
      end do
   end subroutine proc
   
end program anon
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Mon Oct 07, 2013 5:52 pm    Post subject: Reply with quote

Thanks. I have logged this for investigation.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Fri Oct 11, 2013 4:42 pm    Post subject: Reply with quote

Thanks Paul.

One thing to note is if you change foo(*) to foo(: ) to make it Standard conforming, the code prints 0, 2 on each line, which isn't correct.

This shows that the default initialisation caused by the use of Intent(Out) isn't being done. Wink
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl


Last edited by davidb on Sat Oct 12, 2013 11:11 am; edited 1 time in total
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


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

PostPosted: Fri Oct 11, 2013 6:19 pm    Post subject: Reply with quote

Thanks. Conversion from smiley to Fortran is fortunately quite simple!
Back to top
View user's profile Send private message AIM Address
PaulLaidler
Site Admin


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

PostPosted: Wed Mar 26, 2014 3:50 pm    Post subject: Reply with quote

This bug has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Thu Mar 27, 2014 8:39 pm    Post subject: Reply with quote

Thanks Paul. I can't wait for the next release.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Apr 26, 2014 11:45 am    Post subject: Reply with quote

With the new version, does the following code work?

It should print 444 but version 7 is printing 222, which is wrong.

Sorry to be a pain. But as there are 2 bugs in the above code I need to know which one was fixed, or if both were.

Code:

program anon

    implicit none
     
    type foo_t
       integer :: a = 444
    end type foo_t

    type (foo_t) :: foo
     
    foo%a = 222
     
    call proc(foo)

    print *, foo%a, ' <-- should print 444'
 
 contains

    subroutine proc(foo)
       type (foo_t), intent(out) :: foo
       print *,'proc called'
    end subroutine proc
     
 end program anon

_________________
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 26, 2014 4:17 pm    Post subject: Reply with quote

For the next release...

The assumed size array now produces an error.
The assumed shape array now gives the right answer.

The latest example (not passing an array) is a new issue and it still fails.
I will log this for investigation.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Apr 26, 2014 5:51 pm    Post subject: Reply with quote

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



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sat Aug 09, 2014 8:52 pm    Post subject: Re: Reply with quote

PaulLaidler wrote:
For the next release...
The assumed size array now produces an error.
The assumed shape array now gives the right answer.


Both working in 7.10.

PaulLaidler wrote:

The latest example (not passing an array) is a new issue and it still fails.
I will log this for investigation.


Confirmed.

Thanks Paul.
_________________
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: Wed Jan 14, 2015 2:34 pm    Post subject: Reply with quote

The latter bug has now been fixed for the next release.
Back to top
View user's profile Send private message AIM Address
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Thu Jan 15, 2015 8:34 am    Post subject: Reply with quote

Brilliant! Thanks a lot Paul.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
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