Skip to content

Commit 77fc494

Browse files
committed
[stdlib] Add note about pointer alignment for subtraction
1 parent a14daa0 commit 77fc494

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

stdlib/public/core/UnsafePointer.swift.gyb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,13 @@ public struct ${Self}<Pointee>
812812
/// With pointers `p` and `q`, the result of `p.distance(to: q)` is
813813
/// equivalent to `q - p`.
814814
///
815+
/// Typed pointers are required to be properly aligned for their `Pointee`
816+
/// type. Proper alignment ensures that the result of `distance(to:)`
817+
/// accurately measures the distance between the two pointers, counted in
818+
/// strides of `Pointee`. To find the distance in bytes between two
819+
/// pointers, convert them to `UnsafeRawPointer` instances before calling
820+
/// `distance(to:)`.
821+
///
815822
/// - Parameter end: The pointer to calculate the distance to.
816823
/// - Returns: The distance from this pointer to `end`, in strides of the
817824
/// pointer's `Pointee` type. To access the stride, use
@@ -970,6 +977,13 @@ extension ${Self} {
970977
/// Returns the distance between two pointers, counted as instances of the
971978
/// pointers' `Pointee` type.
972979
///
980+
/// Typed pointers are required to be properly aligned for their `Pointee`
981+
/// type. Proper alignment ensures that the result of the subtraction
982+
/// operator (`-`) accurately measures the distance between the two
983+
/// pointers, counted in strides of `Pointee`. To find the distance in bytes
984+
/// between two pointers, convert them to `UnsafeRawPointer` instances
985+
/// before subtracting.
986+
///
973987
/// - Parameters:
974988
/// - lhs: A pointer.
975989
/// - rhs: Another pointer.

0 commit comments

Comments
 (0)