diff options
| author | bors <bors@rust-lang.org> | 2013-12-16 13:16:40 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-12-16 13:16:40 -0800 |
| commit | 000cda611f8224ac780fa37432f869f425cd2bb7 (patch) | |
| tree | 8f2cd23c7c474ea561e2bcd2447ffa8e9d91cc6f | |
| parent | 35e5056b6a89d97d386416da44058cc736994ba9 (diff) | |
| parent | 16f69b225bdda1000610c5afda5d37dfd52ca306 (diff) | |
| download | rust-000cda611f8224ac780fa37432f869f425cd2bb7.tar.gz rust-000cda611f8224ac780fa37432f869f425cd2bb7.zip | |
auto merge of #11002 : pnkfelix/rust/fsk-improve-doc-for-ptr-offset, r=alexcrichton
Spell out the units used for the `offset` argument, so that people do not try to scale to units of bytes themselves.
| -rw-r--r-- | src/libstd/ptr.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libstd/ptr.rs b/src/libstd/ptr.rs index e2dda826765..162e46c53ae 100644 --- a/src/libstd/ptr.rs +++ b/src/libstd/ptr.rs @@ -21,7 +21,9 @@ use util::swap; #[cfg(not(test))] use cmp::{Eq, Ord}; -/// Calculate the offset from a pointer +/// Calculate the offset from a pointer. +/// The `count` argument is in units of T; e.g. a `count` of 3 +/// represents a pointer offset of `3 * sizeof::<T>()` bytes. #[inline] pub unsafe fn offset<T>(ptr: *T, count: int) -> *T { intrinsics::offset(ptr, count) @@ -29,6 +31,8 @@ pub unsafe fn offset<T>(ptr: *T, count: int) -> *T { /// Calculate the offset from a mut pointer. The count *must* be in bounds or /// otherwise the loads of this address are undefined. +/// The `count` argument is in units of T; e.g. a `count` of 3 +/// represents a pointer offset of `3 * sizeof::<T>()` bytes. #[inline] pub unsafe fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T { intrinsics::offset(ptr as *T, count) as *mut T |
