Skip to content

Add a pointer type #6

Description

@caoimhebyrne

A pointer type (*T) is similar to a reference type, with the exception that it allows for pointer arithmetic (offset). An example API would look like:

// Retrieves the value that this pointer refers to.
public func <T> *T.read() -> T;

// Sets the value within this pointer to a value (`@ptr = value`).
public func <T> *T.set(value: T);

// Returns a new pointer, which has been offset by `count` units of `T`.
public func <T> *T.offset(count: i64) -> This;

Some questions that still need to be answered:

  1. Should read return an optional?
  2. How can a pointer be casted to another type?
  3. Is there anything that can be done to ensure that the caller calls memory::free on a pointer?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions