Skip to content

Commit 1119964

Browse files
committed
add warning regarding swap on characters
1 parent 3a2fa03 commit 1119964

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

doc/specs/stdlib_math.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ Elemental subroutine.
8585
`lhs`: scalar or array of any of the intrinsic types `integer`, `real`, `complex`, `logical`, `character`, `string_type`, `bitset` type. This argument is `intent(inout)`.
8686
`rhs`: scalar or array of any of the intrinsic types `integer`, `real`, `complex`, `logical`, `character`, `string_type`, `bitset` type. This argument is `intent(inout)`.
8787

88-
Note: All arguments must have same `type` and same `kind`.
88+
##### Note
89+
All arguments must have same `type` and same `kind`.
8990

90-
#### Example
91+
**WARNING**: For fix size characters with different length, the `swap` subroutine will truncate the longest amongst `lhs` and `rhs`. To avoid truncation it is possible to pass a subsection of the string.
92+
93+
#### Examples
9194

9295
```fortran
9396
{!example/math/example_math_swap.f90!}

example/math/example_math_swap.f90

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ program example_math_swap
2424
end block
2525

2626
block
27-
character(5) :: x, y
28-
x = 'abcde'
29-
y = 'fghij'
30-
call swap(x,y)
27+
character(4) :: x
28+
character(6) :: y
29+
x = 'abcd'
30+
y = 'efghij'
31+
call swap(x,y) ! x=efgh, y=abcd
32+
33+
x = 'abcd'
34+
y = 'efghij'
35+
call swap(x,y(1:4)) ! x=efgh, y=abcdij
3136
end block
3237

3338
block

0 commit comments

Comments
 (0)