Skip to content

Commit 483ee87

Browse files
authored
Update cmplx-real-pointers.txt
1 parent b75b057 commit 483ee87

File tree

1 file changed

+28
-22
lines changed

1 file changed

+28
-22
lines changed

proposals/cmplx-real-pointers.txt

+28-22
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ Date: 2023-12-29
88

99
The proposal is to allow a complex pointer to be associated to a real
1010
array, and similarly to allow a real pointer to be associated to a
11-
complex scalar or array. Going further, this could be extended to
12-
argument association between entities of type real and complex.
11+
complex scalar or array.
1312

1413
2. Motivation
1514

@@ -88,9 +87,9 @@ used, with additional rules and restrictions:
8887
- `c` can also be a complex scalar pointer, in the case where r is a
8988
rank-1 array of size 2
9089
- the size of the first dimension of `r` shall be even
91-
- `c%re` refers to the same storage than `r(1::2)` (rank-1), or
90+
- `c%re` refers to the same storage as `r(1::2)` (rank-1), or
9291
`r(1::2,:)` (rank-2), etc...
93-
- `c%im` refers to the same storage than `r(2::2)` (rank-1), or
92+
- `c%im` refers to the same storage as `r(2::2)` (rank-1), or
9493
`r(2::2,:)` (rank-2), etc...
9594

9695
`r => c`
@@ -106,8 +105,7 @@ used, with additional rules and restrictions:
106105
3.2 Alternative syntaxes
107106

108107
If one wants to make the association between two different types more
109-
explicit, also catching possible mistakes at compile time, a new
110-
syntax may be introduced:
108+
explicit and more type-safe, a new syntax may be introduced:
111109

112110
Alternative syntax 1:
113111
```
@@ -127,24 +125,14 @@ c => complex :: r
127125
r => real :: c
128126
```
129127

130-
4. Argument association
128+
Something generic (that is, not `complex_pointer()` or `real_pointer()`)
129+
may be desirable in case other inter-type pointer association would be
130+
allowed in future versions of the standard.
131131

132-
For full consistency, argument association between the real and
133-
complex types of the same kind could (or should?) be allowed, without
134-
having to use intermediate pointers. For, if pointer association
135-
is possible and allowed, the argument association is also possible
136-
with the exact same rules and restrictions (contiguity, etc...).
137132

138-
Should the argument association be allowed, then the default pointer
139-
association syntax should be kept, without considering the alternative
140-
syntaxes. The main added value of the alternative syntaxes is to allow
141-
an additional check at compile time (that the association between two
142-
different type is really intentional): not only this is not critical,
143-
but this check cannot be performed with the argument association.
133+
4. Issues / Objections / Limitations
144134

145-
5. Objections
146-
147-
5.1. Memory layout
135+
4.1. Memory layout
148136

149137
This proposal would constraint the memory layout of the complex type
150138
beyond what the current standard does. However, the required layout
@@ -166,10 +154,28 @@ such a layout is possible at all). In this layout, a complex array is
166154
stored with all the real parts first, then all the imaginary parts.
167155
In this case, `c%re` would refer to the same storage as `r(1:n/2)`.
168156

169-
6. References
157+
4.2. Argument association
158+
159+
Allowing a real actual argument to be associated to a complex dummy
160+
argument -and vice-versa- has also been considered, but it would raise
161+
backward compatibility issues. So this part has been dropped.
162+
163+
4.3. Alignment
164+
165+
Considering for instance a default real type stored on 4 bytes, the
166+
default complex type is stored on 8 bytes. Compilers may prefer/want to
167+
align complex arrays on 16 bytes boundaries, which cannot be guaranteed
168+
if a complex pointer is associated to an arbitrary real array
169+
(e.g. `c => r(2:)`). If this is a problem, the pointer association may be
170+
allowed only in the other way (real pointer associated to a complex array).
171+
172+
173+
5. References
170174

171175
Fortran Discourse Forum:
172176
https://fortran-lang.discourse.group/t/complex-type-storage-again/7020
177+
https://fortran-lang.discourse.group/t/implicit-real-complex-conversion-in-fortran/7381
173178

174179
Fortran Proposal Github:
175180
https://github.com/j3-fortran/fortran_proposals/issues/323
181+
https://github.com/j3-fortran/fortran_proposals/pull/325

0 commit comments

Comments
 (0)