Skip to content

Commit f705346

Browse files
committed
Added discussion of undefined behavior
Added discussion of the undefined behavior that can occur when the bitset "sizes" for the two bitset arguments to "binary" procedures do not agree. [ticket: X]
1 parent 9f690fd commit f705346

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

doc/specs/stdlib_bitsets.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,30 @@ title: Bitsets
1010

1111
The `stdlib_bitsets` module implements bitset types. A bitset is a
1212
compact representation of a sequence of `bits` binary values. It can
13-
equivalently be considered as a sequence of logical values or as a subset of
14-
the integers 0 ... `bits-1`. The bits are indexed from 0 to
13+
equivalently be considered as a sequence of logical values or as a
14+
subset of the integers 0 ... `bits-1`. The bits are indexed from 0 to
1515
`bits(bitset)-1`. A bitset is used when space savings are critical in
1616
applications that require a large number
1717
of closely related logical values.
18-
It may also improve performance by reducing memory traffic. To implement
19-
bitsets the module
18+
It may also improve performance by reducing memory traffic. To
19+
implement bitsets the module
2020
defines three bitset types, multiple constants, a character string
2121
literal that can be read to and from strings and formatted files, a
2222
simple character string literal that can be read to and from strings,
2323
assignments, procedures, methods, and operators. Note that the module
24-
assumes two's complement integers, but all current Fortran 95+ processors use such integers.
24+
assumes two's complement integers, but all current Fortran 95+
25+
processors use such integers.
26+
27+
Note that the module defines a number of "binary" procedure,
28+
procedures with two bitset arguments. These arguments must be of the
29+
same type and should have the same number of `bits`. For reasons of
30+
performance the module does not enforce the `bits` constraint, but
31+
failure to obey that constraint results in undefined behavior. This
32+
undefined behavior includes undefined values for those bits that
33+
exceed the defined number of `bits` in the smaller bitset. The
34+
undefined behavior may also include a "segmentation fault" for
35+
attempting to address bits in the smaller bitset, beyond the defined
36+
number of `bits`. Other problems are also possible.
2537

2638

2739
## The module's constants

0 commit comments

Comments
 (0)