"RawPointer" (Compiled Type)

"RawPointer"::[t]

represents a pointer to an object with type t, suitable for use with external libraries.

Details

  • "RawPointer"::[t] is equivalent to t* in C.

Constructors

  • ToRawPointer can be used to create a pointer object that is valid until the enclosing function returns.

Properties

  • Information[ptr,"BaseType"] for ptr of type "RawPointer"::[t] gives "TypeSpecifier"::[t].
  • FromRawPointer[ptr] returns the value pointed to by ptr.

Conversions

    "CArray"

  • Cast can be used to bitcast pointers to and from C arrays.
  • "OpaqueRawPointer"

  • Cast can be used to bitcast pointers to and from opaque pointers.

Run-Time Errors

  • Dereferencing a pointer with FromRawPointer is an unsafe operation. Attempting to dereference an invalid pointer can lead to a crash.

Examples

Basic Examples  (2)

Create a "RawPointer"::["MachineInteger"], then dereference it:

Represent a library function that returns its results by modifying a pointer:

Compile a program that uses the function: