Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29302 Discussions

Array and structure constructors for types with allocatable components

IanH
Honored Contributor III
1,138 Views
Due to cost-of-living increases, I decided that family members were only getting integers as presents this season. I used ifort 12.0.1 to help make my shopping lists, but things ended up in chaos...

[fortran]MODULE XMasLists
  IMPLICIT NONE 
  TYPE :: ListType
    CHARACTER(7) :: who_is_it_for
    INTEGER, ALLOCATABLE :: what_are_they_getting(:)
  END TYPE ListType  
CONTAINS
  SUBROUTINE MakeTheList(the_list)
    TYPE(ListType), INTENT(INOUT), ALLOCATABLE :: the_list(:)
    !****
    ALLOCATE(the_list(0))        
    ! Mum gets a single six.
    the_list = [the_list, ListType('OldDuck', [6])]     
    ! Dad gets a five.
    the_list = [the_list, ListType('OldMan',  [5])]     
    ! A three and a four for the wife
    the_list = [the_list, ListType('Missus', [3, 4])]    
    ! A one and a two for the kid
    the_list = [the_list, ListType('RugRat', [1, 2])] 
  END SUBROUTINE MakeTheList
  
  SUBROUTINE PrintTheList(list)  
    TYPE(ListType), INTENT(IN) :: list(:)    
    INTEGER :: i    
    !****
    DO i = 1, SIZE(list)
      PRINT "('The ',A7,': ',999(I0,:,','))", list(i)%who_is_it_for,  &
          list(i)%what_are_they_getting
    END DO    
  END SUBROUTINE PrintTheList
END MODULE XMasLists

PROGRAM AllMyFamilyGetsForChristmasIsIntegers
  USE XMasLists
  IMPLICIT NONE  
  TYPE(ListType), ALLOCATABLE :: the_list(:)  
  !***
  CALL MakeTheList(the_list)
  CALL PrintTheList(the_list)
END PROGRAM AllMyFamilyGetsForChristmasIsIntegers
[/fortran]

[plain]H:\\Projects\\xmas-shopping>ifort /check:all /warn:all /standard-semantics integer-list.f90
Intel Visual Fortran Compiler XE for applications running on IA-32, Version 1
2.0.1.127 Build 20101116
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:integer-list.exe
-subsystem:console
integer-list.obj

H:\\Projects\\xmas-shopping>integer-list.exe
The OldDuck: 6
The OldMan : 6
The Missus : 0,0
The RugRat : 1,2[/plain]


I gave the missus lots of zeros last year! Looks like I'll be seeing the new year in from the dog-house again...
0 Kudos
12 Replies
Steven_L_Intel1
Employee
1,138 Views
Hmm- this looks like a regift of a bug we received earlier this year. I'm out of the office this week but will check with our elves when I get back.
0 Kudos
abhimodak
New Contributor I
1,138 Views
Hi Ian and Steve

On my computer (WinXP-Pro 64, VS2005, composer update 1) I get

The OldDuck: 6
The OldMan : 6
The Missus : 6,4
The RugRat : 1,2

Abhi
0 Kudos
Steven_L_Intel1
Employee
1,138 Views
That's just as wrong, unfortunately...
0 Kudos
IanH
Honored Contributor III
1,138 Views
Another one for your elves... attempts to buy some zero length CHARACTER arrays on the cheap at the post Christmas sales didn't get very far...

[fortran]PROGRAM empty_character_array_constructors
  IMPLICIT NONE  
  INTEGER, PARAMETER :: some_length = 11  
  TYPE some_type
    CHARACTER(some_length), ALLOCATABLE :: some_component(:)  
  END TYPE some_type  
  TYPE(some_type), ALLOCATABLE :: some_array(:)
  !****  
  some_array = [ some_type([CHARACTER(LEN=some_length) :: ]) ]  
END PROGRAM empty_character_array_constructors
  [/fortran]


[plain]>ifort /warn:all /check:all /standard-semantics empty-character-array-constructors.f90
Intel Visual Fortran Compiler XE for applications running on IA-32, Version 12.0.1.127 Build 20101116
Copyright (C) 1985-2010 Intel Corporation.  All rights reserved.

fortcom: Fatal: There has been an internal compiler error (C0000005).
compilation aborted for empty-character-array-constructors.f90 (code 1)[/plain]
0 Kudos
Steven_L_Intel1
Employee
1,138 Views
Hmm - must have been "Bad Santa" that day. Thanks.
0 Kudos
Steven_L_Intel1
Employee
1,138 Views
Santa's elves tell me that the first problem, with the integer gifts, is fixed in 12.0 Update 2, and I checked the list to be sure. The second problem, with the empty array in the constructor, has been entered onto the "naughty" list as DPD200165369.
0 Kudos
psantos
Beginner
1,138 Views
Steve,

Are you absolutely sure that the first problem, the one with integer gifts, was corrected? I have just tried it out and and I'm getting wrong answers in Fortran Composer 12 Update 2.

Pedro
0 Kudos
Steven_L_Intel1
Employee
1,138 Views
Oops. The results are better in Update 2 but not completely correct. Thanks for the second look.

[plain]c:Projects>ifort /standard-semantics gifts.f90
Intel Visual Fortran Compiler XE for applications running on IA-32, Version 1
2.0.2.154 Build 20110112
Copyright (C) 1985-2011 Intel Corporation.  All rights reserved.

Microsoft  Incremental Linker Version 10.00.30319.01
Copyright (C) Microsoft Corporation.  All rights reserved.

-out:gifts.exe
-subsystem:console
gifts.obj

c:Projects>gifts.exe
The OldDuck: 6
The OldMan : 6
The Missus : 3,4
The RugRat : 1,2[/plain]

The OldMan got a duplicate gift.
0 Kudos
psantos
Beginner
1,138 Views
Steve,

Actually I have different results:
[bash]------ Build started: Project: DerivedTypesError, Configuration: Debug Win32 ------
Compiling with Intel Visual Fortran Compiler XE 12.0.2.154 [IA-32]...
main.f90
Linking...

The OldDuck: -572662307
The OldMan : -572662307
The Missus : -842150451,-842150451
The RugRat : 1,2[/bash]

Only the last family member is correct... Much worse than yours. I've taken a look and when "MakeTheList" return the data get corrupted. Actually inside the subroutine "MakeTheList" everything is right (until the return). Hope this helps.

Pedro


0 Kudos
Steven_L_Intel1
Employee
1,138 Views
My guess is that you did not add /standard-semantics or /assume:realloc_lhs. One of these is required to make this program work at all.
0 Kudos
psantos
Beginner
1,138 Views
Steve,

The results I shown to you are compiled with the /standard-semantic switch. I'm aware that this is very important. One more thing, if a compile in Release x64 I get the same answer as you. But this is the only configuration that does the same answer as yours.

Pedro
0 Kudos
Steven_L_Intel1
Employee
1,138 Views
The internal compiler error is expected to be fixed in update 3. The wrong result is still being worked on and is issue DPD200166796.
0 Kudos
Reply