# Beginner question on coarrays

**URL:** <https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179>\
**Category:** Help\
**Created:** [October 15, 2026, 10:38am UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179 "2026-10-15T10:38:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vvanag](https://avatars.discourse-cdn.com/v4/letter/v/6a8cbe/32.png) [@vvanag](https://fortran-lang.discourse.group/u/vvanag)\
**Post date:** [October 15, 2026, 10:38am UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/1 "2026-10-15T10:38:19Z")

</div>

In the book Modern Fortran by Milan Curcic, " **7.4.2 Allocating dynamic coarrays"**

I see that for allocatable coarrays, the definition is

```auto
real, dimension(:), codimension[:], allocatable :: a

```

and not

```auto
real, dimension(:), codimension[*], allocatable :: a

```

Why is that?

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [October 15, 2026, 11:13am UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/2 "2026-10-15T11:13:23Z")

</div>

Fortran tries to adhere to a pattern, when it comes to using `*` and `:`

`:` generally means that the variable in question may have different values for the corresponding attribute during execution of the code where it is in scope. The whole idea of `ALLOCATABLE` is indeed that, in that scope, its co-extents could be one value in some statement, and a different in another statement. Other examples: assumed-shape arrays `REAL, INTENT(IN) :: X(:,:)`, deferred-shape arrays `POINTER, REAL :: Y(:)`.

`*` generally means that the value of that attribute is not known at compile-time but will remain fixed during the scope that name comes into existence for. Other examples: assumed-size arrays `REAL :: A(LDA,*)`, implied-shape constant arrays `PARAMETER, INTEGER :: I(*)=[1,2,3]`

For the `CODIMENSION`, since the number of images is fixed at the beginning of execution and will never change, the `*` is the appropriate symbol.

---

<div class="post-metadata">

**Author:** ![vvanag](https://avatars.discourse-cdn.com/v4/letter/v/6a8cbe/32.png) [@vvanag](https://fortran-lang.discourse.group/u/vvanag)\
**Post date:** [October 15, 2026, 1:11pm UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/3 "2026-10-15T13:11:26Z")

</div>

According to your insights, where I agree, here is what my gcc disitribution reports when I change `:` with `*`.

```auto
weather_stats_parallel.f90:13:24:

13 | real, allocatable :: gather(:)[*]
| 1 ~~~~~~~~~~~
Error: Allocatable coarray variable 'gather' at (1) must have deferred shape
make: *** [makefile:22: weather_stats_parallel] Error 1

```

this is unexpected for me.

PS: I use `gcc-16.2.0-64` from [equation.com](http://equation.com).

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [October 15, 2026, 2:19pm UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/4 "2026-10-15T14:19:30Z")

</div>

At declaration, you must use `(:)[:]`. Or `CODIMENSION[:], DIMENSION(:)` and nothing but the name at the end.

Can you show us the ALLOCATE statement?

---

<div class="post-metadata">

**Author:** ![vvanag](https://avatars.discourse-cdn.com/v4/letter/v/6a8cbe/32.png) [@vvanag](https://fortran-lang.discourse.group/u/vvanag)\
**Post date:** [October 15, 2026, 3:25pm UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/5 "2026-10-15T15:25:27Z")

</div>

The book gets it right

`allocate(gather(grid_size)[*])`

and the declaration is as I described

```auto
real(real32), allocatable :: gather(:)[:] 

```

the error happens when I take the “initiative” to change it as

```auto
real(real32), allocatable :: gather(:)[*] 

```

in the source code. I get why I caused the error, I do not get why the definition of the book/standard is not making sense. Because for a scalar is like that

```auto
integer :: a[*] 

```

It is unintuitive to me.

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [October 15, 2026, 4:42pm UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/6 "2026-10-15T16:42:04Z")

</div>

Well, the syntax in the scalar nonallocatable case declaration `a[*]` looks exactly like the syntax in the `ALLOCATE`, `[*]`. `ALLOCATABLE` variables need `:` at declaration and must use `*` (as the last one) at allocation time. Non-allocatables must use `*` at declaration.

---

<div class="post-metadata">

**Author:** ![vvanag](https://avatars.discourse-cdn.com/v4/letter/v/6a8cbe/32.png) [@vvanag](https://fortran-lang.discourse.group/u/vvanag)\
**Post date:** [October 16, 2026, 7:25am UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/7 "2026-10-16T07:25:47Z")

</div>

Thank you. It makes sense now. When in Fortran do as Fortran heads do!

---

<div class="post-metadata">

**Author:** ![themos](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/themos/32/521_2.png) [@themos](https://fortran-lang.discourse.group/u/themos)\
**Post date:** [October 16, 2026, 9:43am UTC](https://fortran-lang.discourse.group/t/beginner-question-on-coarrays/11179/8 "2026-10-16T09:43:11Z")

</div>

I suppose Fortran could allow an `ALLOCATE( x(N,*) )` to mean grab as many columns as possible, but it currently does not. It would be rather cool…
