FIX: F2124 or Incorrect Results From Structure Array UseLast reviewed: September 11, 1997Article ID: Q72760 |
5.00 5.10 | 5.00 5.10
MS-DOS | OS/2kbtool kbbuglist kbfixlist kberrmsg kbcode The information in this article applies to:
SYMPTOMSAn attempt to compile an application fails and the compiler may generate the following message:
F2124: CODE GENERATION ERROR Contact Microsoft Technical SupportAlternately, the application compiles without error but does not generate any output.
CAUSEThe application declares an array of structures that contain REAL*4 elements, REAL*8 elements, or mixed-type elements (for example, one INTEGER*4 element and one COMPLEX*8 element). The application attempts to write the entire array without specifying a subscript. The same code generation error can occur if the application declares an assumed-size array in a subprogram and the compiler command line specifies the /Od compiler option switch. In this case, the types of the structure elements do not effect the error. If the command line does not include /Od compiler option switch, the error message may not appear, but the application does not produce any output. Neither the ANSI FORTRAN 77 standard nor Microsoft FORTRAN supports printing an entire assumed-size array. The compiler is designed to generate the following error message in this case:
F2727: assumed-size array illegal here RESOLUTIONTo address this error, modify the source code to print each element of the array individually instead of all at once.
STATUSMicrosoft has confirmed this to be a problem in FORTRAN versions 5.0 and 5.1 for MS-DOS and OS/2. This problem was corrected in FORTRAN PowerStation, version 1.0.
MORE INFORMATIONThe following code example demonstrates this problem.
Sample Code #1C Compile options needed: None
STRUCTURE /STRUC/ REAL R END STRUCTURE RECORD /STRUC/ S(10) S.R = 4 WRITE (*, *) S.R ENDTo work around this problem, use an implied-DO loop to print each elements of the array of structures. The following code example demonstrates this approach.
Sample Code #2C Compile options needed: None
STRUCTURE /STRUC/ REAL R END STRUCTURE RECORD /STRUC/ S(10) S.R = 4 WRITE (*, *) (S(I).R, I = 1, 10) ! Print elements using ! implied DO-loop ENDThe following code example, that uses an assumed-size array of structures, compiles without error but does not produce any output.
Sample Code #3C Compile options needed: None
STRUCTURE /STRUC/ REAL R END STRUCTURE RECORD /STRUC/ ST(10) ST.R = 4 CALL SUB(ST) END SUBROUTINE SUB(ST) STRUCTURE /STRUC/ REAL R END STRUCTURE RECORD /STRUC/ ST(*) ! Assumed-sized array declared WRITE (*, *) ST.R ! nothing is output here ENDCompiling this code example with the /Od compiler option switch specified causes a code generation error. An application cannot print an assumed-size array as an array. The application must specify a subscript and print each element individually. One solution to this problem is to use an adjustable- sized array. Pass the length of the structure array to the subprogram with the array itself. Use the array length to terminate the loop that prints the individual array elements. The following code example demonstrates this process.
Sample Code #4C Compile options needed: None
PARAMETER (LENGTH = 10) STRUCTURE /STRUC/ REAL J END STRUCTURE RECORD /STRUC/ ST(LENGTH) ST.J = 4 CALL SUB(ST, LENGTH) END SUBROUTINE SUB(ST, LENGTH) STRUCTURE /STRUC/ REAL J END STRUCTURE INTEGER LENGTH RECORD /STRUC/ ST(LENGTH) WRITE (*, *) (ST(I).J, I = 1, LENGTH) ! Print array elements ! in implied DO-loop END |
Additional reference words: 5.00 5.10 buglist5.00 buglist5.10 fixlist1.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |