View previous topic :: View next topic |
Author |
Message |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Mon Oct 07, 2013 4:02 pm Post subject: Assumed size array of derived type + default initialization |
|
|
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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Mon Oct 07, 2013 5:52 pm Post subject: |
|
|
Thanks. I have logged this for investigation. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Fri Oct 11, 2013 4:42 pm Post subject: |
|
|
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.  _________________ 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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Fri Oct 11, 2013 6:19 pm Post subject: |
|
|
Thanks. Conversion from smiley to Fortran is fortunately quite simple! |
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Wed Mar 26, 2014 3:50 pm Post subject: |
|
|
This bug has now been fixed for the next release. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Mar 27, 2014 8:39 pm Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sat Apr 26, 2014 11:45 am Post subject: |
|
|
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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Sat Apr 26, 2014 4:17 pm Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sat Apr 26, 2014 5:51 pm Post subject: |
|
|
OK Thanks. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sat Aug 09, 2014 8:52 pm Post subject: Re: |
|
|
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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Wed Jan 14, 2015 2:34 pm Post subject: |
|
|
The latter bug has now been fixed for the next release. |
|
Back to top |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Thu Jan 15, 2015 8:34 am Post subject: |
|
|
Brilliant! Thanks a lot Paul. _________________ Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl |
|
Back to top |
|
 |
|