- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
When I compile the following program using the Intel Fortran compiler,
there are no error or warning messages printed. However, I think the code
has a bug because a 2D array is initialized with a 1D array.
[fortran]program test_array implicit none integer:: a(2,2) = (/ 1, 2, 3, 4 /) !!! print*, sum(a) stop end program test_array [/fortran]
Roman
Link Copied
3 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This code is legal and standard Fortran. The standard (F2008) says:
"... if necessary, the value is converted according to the rules of intrinsic assignment (7.2.1.3) to a value that agrees in type, type parameters, and shape with the variable."
Then 7.2.1.3 says:
"If the variable is an array, the assignment is performed element-by-element on corresponding array elements of the variable and expr."
This is a bit looser than if you had an actual assignment statement but matches what a DATA statement can do.
"... if necessary, the value is converted according to the rules of intrinsic assignment (7.2.1.3) to a value that agrees in type, type parameters, and shape with the variable."
Then 7.2.1.3 says:
"If the variable is an array, the assignment is performed element-by-element on corresponding array elements of the variable and expr."
This is a bit looser than if you had an actual assignment statement but matches what a DATA statement can do.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the reply.
The reason for the question is that when I compiled the same code using gfortran, I got the
following error:
Error: Incompatible ranks 2 and 1 in assignment at (1)
So perhaps, there is a problem in gfortran.
Also, the Intel compiler does issue a warning if parameter is used.
[bash]integer,parameter:: a(2,2) = (/ 1, 2, 3, 4 /) !!! [/bash]warning #6366: The shapes of the array expressions do not conform.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The warning for the parameter is correct.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page