# Declaring \*assumed size\* array with constant constructor

**URL:** <https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010>\
**Category:** Language enhancement\
**Created:** [December 18, 2023, 3:36pm UTC](https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010 "2023-12-18T15:36:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [December 18, 2023, 3:36pm UTC](https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010/1 "2023-12-18T15:36:58Z")

</div>

Fortran allows constant arrays to be declared with _assumed-size_ syntax and constant expression constructor, like

```fortran
integer, parameter :: tmpa(*) = [0,1,2,3,4,5]

```

Why couldn’t it be a _non constant_ array? The following workaround does the job:

```fortran
integer, parameter :: tmpa(*) = [0,1,2,3,4,5]
integer :: arr(size(tmpa))=tmpa

```

So why not just allow

```fortran
integer :: arr(*)=[0,1,2,3,4,5]

```

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [December 18, 2023, 5:08pm UTC](https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010/2 "2023-12-18T17:08:41Z")

</div>

You’d then run into the issue that `arr` could be a dummy argument, where assumed-size is an existing feature. It would be messy to have to have to assign a different meaning to (\*) depending on whether arr was a dummy argument or not. There was no such issue with `parameter`.

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [December 18, 2023, 7:28pm UTC](https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010/3 "2023-12-18T19:28:43Z")

</div>

It seems, however, that a dummy argument specification in a procedure **cannot** have an initializer. I am not sure whether it is standard-forbidden but both `gfortran` and `ifort/ifx` report an error, not only on an array, but also on scalar dummy.  
So, I think, that would not be a serious issue. Also, `C` has always allowed such a declaration, as in `int arr`[]`={0,1,2,3,4,5};`

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [December 18, 2023, 7:59pm UTC](https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010/4 "2023-12-18T19:59:56Z")

</div>

I’m not saying it would be ambiguous, but it would be complicated and maybe confusing to define, for something that can already be done another way.

---

<div class="post-metadata">

**Author:** ![Pap](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pap/32/1305_2.png) [@Pap](https://fortran-lang.discourse.group/u/Pap)\
**Post date:** [December 18, 2023, 9:07pm UTC](https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010/5 "2023-12-18T21:07:59Z")

</div>

> [@msz59](#):
>
> So why not just allow
> 
> ```auto
> integer :: arr(*)=[0,1,2,3,4,5]
> 
> ```

From time to time, I catch myself trying to do something like that, only to realize it doesn’t work… and then I remember I tried the same in the past - but forgot it just won’t work in the meantime. 😆  
I guess the fact I tried this more than once over the years means it’s somewhat logical for a user to expect this is valid. I’m sure it’s not just me and @msz59 who tried something similar. However I think @sblionel 's explanation why this doesn’t work makes sense. Also, the fact C does indeed allow something like that with its “arrays” doesn’t mean much, if anything.

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [December 18, 2023, 9:17pm UTC](https://fortran-lang.discourse.group/t/declaring-assumed-size-array-with-constant-constructor/7010/6 "2023-12-18T21:17:44Z")

</div>

Edit: the syntax `integer, parameter :: tab(*) = [0,1,2,3]` is called _implied-shape_, not _assumed-size_. So it would be not only unambiguous but quite a different feature. The asterisk `*` serves so many purposes in Fortran 🙂
