# Question about \`reshape(\[real ::\],n)\`

**URL:** <https://fortran-lang.discourse.group/t/question-about-reshape-real-n/3296>\
**Category:** Help\
**Created:** [April 22, 2022, 4:44pm UTC](https://fortran-lang.discourse.group/t/question-about-reshape-real-n/3296 "2022-04-22T16:44:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcosta](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pcosta/32/5504_2.png) [@pcosta](https://fortran-lang.discourse.group/u/pcosta)\
**Post date:** [April 22, 2022, 4:44pm UTC](https://fortran-lang.discourse.group/t/question-about-reshape-real-n/3296/1 "2022-04-22T16:44:48Z")

</div>

Dear all,

The right-hand side automatically allocating `x` appears to be an array with dimensions `n(1),n(2),n(3)`, but I don’t really understand what is happening there. Is this valid Fortran? It compiles successfully on ifort, but not the latest gfortran (see answer below) and nvfortran.

```fortran
implicit none
integer, parameter :: n(3) = [3,2,1]
real, allocatable :: x(:,:,:)
x = reshape([real ::],n)
end

```

Thanks!

PS: inspired by this SO answer: [fortran - Allocate Multiple Arrays with Single Shape - Stack Overflow](https://stackoverflow.com/a/50710504)

---

<div class="post-metadata">

**Author:** ![shahmoradi](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/shahmoradi/32/3151_2.png) [@shahmoradi](https://fortran-lang.discourse.group/u/shahmoradi)\
**Post date:** [April 22, 2022, 5:07pm UTC](https://fortran-lang.discourse.group/t/question-about-reshape-real-n/3296/2 "2022-04-22T17:07:37Z")

</div>

This is an `ifort` compiler bug, in my opinion. If the size of `source = [real ::]` is less than `x`, then the `pad` argument should be present if I remember correctly. [The latest `gfortran` detects the problem correctly](https://godbolt.org/z/sEEKs6aqK). It would be great to report this ifort bug in [Intel Fortran Forum](https://community.intel.com/t5/Intel-Fortran-Compiler/bd-p/fortran-compiler). Just put `compiler bug` or something similar in the title for the developers to notice.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [April 22, 2022, 5:12pm UTC](https://fortran-lang.discourse.group/t/question-about-reshape-real-n/3296/3 "2022-04-22T17:12:21Z")

</div>

On WSL2, my gfortran is GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, and it compiles the code you gave. On Windows I have GNU Fortran (GCC) 12.0.1 20220213 installed from [equation.com](http://equation.com) , and it says

```auto
reshape_question.f90:4:12:

    4 | x = reshape([real ::],n)
      | 1
Error: Without padding, there are not enough elements in the intrinsic RESHAPE source at (1) to match the shape

```

Adding the suggested PAD argument, the code

```auto
implicit none
integer, parameter :: n(3) = [3,2,1]
real, allocatable :: x(:,:,:)
x = reshape([real ::],n,pad=[-1.0,1.0])
print*,shape(x)
print*,x
end

```

compiles and runs, giving

```auto
           3 2 1
  -1.00000000 1.00000000 -1.00000000 1.00000000 -1.00000000 1.00000000

```

Metcalf, Reid, and Cohen (2018) say

> reshape (source, shape [,pad] [,order] ) returns an array with shape  
> given by the rank-one integer array shape, and type and type parameters those of the  
> array source. The size of shape must be constant, and its elements must not be negative.  
> If pad is present, it must be an array of the same type and type parameters as  
> source. If pad is absent or of size zero, the size of the result must not exceed the size  
> of source.

---

<div class="post-metadata">

**Author:** ![pcosta](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pcosta/32/5504_2.png) [@pcosta](https://fortran-lang.discourse.group/u/pcosta)\
**Post date:** [April 22, 2022, 5:40pm UTC](https://fortran-lang.discourse.group/t/question-about-reshape-real-n/3296/4 "2022-04-22T17:40:50Z")

</div>

Thanks! It seems `nvfortran` still doesn’t digest this:

```nohighlight
$ nvfortran test.f90                                                                                                                                                                                  
NVFORTRAN-S-0074-Illegal number or type of arguments to reshape - keyword argument source (test.f90: 4)
  0 inform, 0 warnings, 1 severes, 0 fatal for MAIN

```
