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 on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29282 Discussions

why cant arr = [1,2,3,4] be accepted?

dave_frank
Beginner
518 Views
integer :: arr(2,2) = [1,2,3,4] ! accepted
arr = [5,6,7,8] ! array shape mismatch complaint
If its acceptable in declaration, why isnt it acceptable inline?
Compiler obviously has ALL the info it needs about arr's shape
to make a DEFAULT FORTRAN DATA (no reshapewanted) assignment.
0 Kudos
1 Reply
Steven_L_Intel1
Employee
518 Views
Hmm. From my reading of the standard, the first shouldn't be accepted either. The standard says:
"If initialization is =initialization-expr, the object name becomes defined with the value determined from initialization-expr in accordance with the rules of intrinsic assignment (7.5.1.4)."
My guess is that the compiler is applying the more generous DATA statement rules, which don't allow you to specify an array constructor but merely a sequence of values.
BTW, I'm ignoring for now your use of the non-standard (in F95, but not F2003) square brackets for the array constructor, as these are not needed to demonstrate the problem.
0 Kudos
Reply