@ptrCast

@ptrCast

@ptrCast(value: anytype) anytype

Converts a pointer of one type to a pointer of another type. The return type is the inferred result type.

Optional Pointers are allowed. Casting an optional pointer which is null to a non-optional pointer invokes safety-checked Undefined Behavior.

@ptrCast cannot be used for:

  • Removing const qualifier, use @constCast.
  • Removing volatile qualifier, use @volatileCast.
  • Changing pointer address space, use @addrSpaceCast.
  • Increasing pointer alignment, use @alignCast.
  • Casting a non-slice pointer to a slice, use slicing syntax ptr[start..end].