|
@@ -315,18 +315,38 @@ check_zero_ptr :: proc(ptr: rawptr, len: int) -> bool {
|
|
Offset a given pointer by a given amount.
|
|
Offset a given pointer by a given amount.
|
|
|
|
|
|
This procedure offsets the pointer `ptr` to an object of type `T`, by the amount
|
|
This procedure offsets the pointer `ptr` to an object of type `T`, by the amount
|
|
-of bytes specified by `offset*size_of(T)`, and returns the pointer `ptr`.
|
|
|
|
|
|
+of bytes specified by `offset * size_of(T)`, and returns the pointer `ptr`.
|
|
|
|
|
|
**Note**: Prefer to use multipointer types, if possible.
|
|
**Note**: Prefer to use multipointer types, if possible.
|
|
*/
|
|
*/
|
|
ptr_offset :: intrinsics.ptr_offset
|
|
ptr_offset :: intrinsics.ptr_offset
|
|
|
|
|
|
/*
|
|
/*
|
|
-Offset a given pointer by a given amount backwards.
|
|
|
|
|
|
+Subtract two pointers of the same type, and return the number of `T` between them.
|
|
|
|
|
|
-This procedure offsets the pointer `ptr` to an object of type `T`, by the amount
|
|
|
|
-of bytes specified by `offset*size_of(T)` in the negative direction, and
|
|
|
|
-returns the pointer `ptr`.
|
|
|
|
|
|
+This procedure subtracts pointer `b` from pointer `a`, both of type `^T`,
|
|
|
|
+and returns an integer count of the `T` between them.
|
|
|
|
+
|
|
|
|
+**Inputs**
|
|
|
|
+- `a`: A pointer to a type T
|
|
|
|
+- `b`: A pointer to a type T
|
|
|
|
+
|
|
|
|
+**Returns**
|
|
|
|
+- `b` - `a` in items of T as an `int`.
|
|
|
|
+
|
|
|
|
+Example:
|
|
|
|
+
|
|
|
|
+ import "core:mem"
|
|
|
|
+ import "core:fmt"
|
|
|
|
+
|
|
|
|
+ ptr_sub_example :: proc() {
|
|
|
|
+ arr: [2]int
|
|
|
|
+ fmt.println(mem.ptr_sub(&arr[1], &arr[0]))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+Output:
|
|
|
|
+
|
|
|
|
+ 1
|
|
*/
|
|
*/
|
|
ptr_sub :: intrinsics.ptr_sub
|
|
ptr_sub :: intrinsics.ptr_sub
|
|
|
|
|