Skip to content

Some questions around what is UB and what is defined when using raw pointers #205

Closed
@elichai

Description

@elichai

Hi,
Read quite a lot of the information out there and I still have a bunch of open questions about pointers, answering them will help me but I also think that it will be good to add to the docs for other people.

This list isn't exhaustive and I'll try to add stuff I see and don't know the answer to:

  1. Passing a pointer to a const variable. -> Is fine but may result in different pointers to the same variable (See Some questions around what is UB and what is defined when using raw pointers #205 (comment))
  2. Mutating a const variable through raw pointer casting. -> Not allowed. (See Some questions around what is UB and what is defined when using raw pointers #205 (comment))
  3. Casting a pointer to usize and back.
  4. Checking alignment via modulo over ptr as usize. (related to 3) (less relevant now that we have align_offset but people still do it in the wild).

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-supportCategory: Supporting a user to solve a concrete problem

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions