Skip to content

Representation of bool, integers and floating points #9

Closed
@nikomatsakis

Description

@nikomatsakis

This issue is to discuss the memory layout for integral and floating point types:

  • bool
  • u8..u128, i8..i128
  • usize, isize
  • f32, f64

For the most part, these are relatively uncontroversial. However, there are some interesting things worth discussing:

  • Unlike other types, there are no #[repr(C)] vs #[repr(Rust)] variants here. The size is always fixed and well-defined across FFI boundaries. The types map to their corresponding integral types in the surrounding C ABI.
  • Prior discussions ([#46156][], [#46176][]) documented bool as a single byte that is either 0 or 1.
  • How is usize intended to be defined on various platforms?
  • Rust currently states that the maximum size of any single value must fit in with isize
    - Can we say a bit more about why? (e.g., ensuring that "pointer diff" is representable
  • Do we want to discuss signaling NaN at all? Specifically: why is it potentially of concern, and are there things that unsafe authors or other folks need to be aware of? (@gankro, for example, wrote that "NaN masking is unnecessary from LLVM's perspective", but I don't really know what that means. =)

Metadata

Metadata

Assignees

Labels

A-layoutTopic: Related to data structure layout (`#[repr]`)S-writeup-assignedStatus: Ready for a writeup and someone is assigned to it

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions