Skip to main content

Wrapping

Struct Wrapping 

Source
pub struct Wrapping {
    pub signed: bool,
    pub pointer: bool,
    pub trap: bool,
}
Expand description

What overflows rather than being undefined, from -fwrapv and its relatives.

C says a signed addition that overflows and a pointer that walks off the end of the object it points into are both undefined, and an optimizer that believes it reads a great deal into every loop: that a counter going up one at a time never turns round, that an index widened to an address may be widened before the arithmetic rather than after, that a bound is reached. These flags withdraw exactly that. They do not make the program mean something else, they make it mean less, and the code that asks for them is code that overflows on purpose and wants the answer the machine gives rather than the answer the standard declines to give.

Two of them because gcc has two, and a build that wants one usually wants the other. Signed arithmetic and pointer arithmetic are separate assumptions and a kernel turns both off.

-ftrapv is the third answer to the first question and is here for that reason. Undefined, wrapping and stopping are the three things a signed overflow can be, and a command line picks one of them: the last of -fwrapv and -ftrapv wins, which is gcc’s behaviour and what makes them one field rather than two that can both be set.

Fields§

§signed: bool

Whether signed arithmetic wraps, from -fwrapv.

§pointer: bool

Whether pointer arithmetic wraps, from -fwrapv-pointer.

§trap: bool

Whether a signed overflow stops the program instead, from -ftrapv.

Never set at the same time as Wrapping::signed, since a program cannot both wrap and stop, and the driver is what keeps that true by clearing each when the other is asked for.

Implementations§

Source§

impl Wrapping

Source

pub const ALL: Self

Both of them, which is what -fno-strict-overflow asks for.

gcc says so itself: its help text for -fstrict-overflow reads “negated as -fwrapv -fwrapv-pointer”, so the older flag is a name for the pair rather than a third knob. And asking for wrapping is asking for not stopping, so this is the whole answer and not two thirds of one.

Source

pub const NONE: Self

Neither, which is the default and what a command line that says nothing about any of this gets.

Trait Implementations§

Source§

impl Clone for Wrapping

Source§

fn clone(&self) -> Wrapping

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Wrapping

Source§

impl Debug for Wrapping

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Wrapping

Source§

fn default() -> Wrapping

Returns the “default value” for a type. Read more
Source§

impl Eq for Wrapping

Source§

impl PartialEq for Wrapping

Source§

fn eq(&self, other: &Wrapping) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Wrapping

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.