Skip to content

Define: "padding bytes" #183

Closed
Closed
@gnzlbg

Description

@gnzlbg

We need a technical term for a byte that is not part of the "value representation" of a type, and we need to at least mention how these bytes currently behave, and provide some guarantees.

For example, a definition that would work today could be:

A "foo" byte is a byte that is not part of the value representation of a type; "foo" bytes can change without any external program action.

For example, the compiler inserts "foo" bytes in structs to pad struct fields to their alignment, or in unions to make the size of the union a multiple of its alignment.

The "foo bytes can change without any external program action" semantics is what we have today. We could guarantee more, but AFAICT right now we do not. I'd prefer if we could have some basic definition that reflects what happens today first, and punt any discussion about guaranteeing more about these bytes to a follow up discussion.

Question: can these "foo" bytes occur due to something that is not padding? If not, then we can call them padding bytes. I can imagine a general mechanism to tell the compiler that some byte of a type is a "foo" byte, similar to what we do for the NonNull and similar types today. That could be useful, for example, for mapping a [u8; N] to some C layout type, where you know the offsets of the bytes in the array that are padding bytes in C.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-paddingTopic: Related to paddingC-terminologyCategory: Discussing terminology -- which term to use, how to define it, adding it to the glossary

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions