returns the value referred to by the pointer p for use in compiled code.
FromRawPointer[array,offset]
returns the value of a C array at an offset.
FromRawPointer
returns the value referred to by the pointer p for use in compiled code.
FromRawPointer[array,offset]
returns the value of a C array at an offset.
Details
- FromRawPointer is only available in compiled code.
- Running FromRawPointer on invalid inputs can lead to crashes.
- FromRawPointer can work with pointers and arrays.
- Usages of FromRawPointer have the following approximate equivalents in C:
-
FromRawPointer[p] *p FromRawPointer[array,offset] array[offset] or *(array+offset)
Examples
open all close allBasic Examples (1)
Scope (1)
Offset (1)
FromRawPointer can extract different elements of an array:
cf = FunctionCompile[Function[{Typed[arg, "Integer64"]}, Module[{arr},
arr = CreateTypeInstance[ "CArray"::["MachineInteger"], 2];
ToRawPointer[arr, 0, arg];
ToRawPointer[arr, 1, arg];
FromRawPointer[arr, 0] + FromRawPointer[arr, 0]
]]]cf[4]Applications (2)
Represent a library function that returns its results by modifying a pointer:
funcDec = LibraryFunctionDeclaration["addonePointer", "compilerDemoBase", {"CInt", "RawPointer"::["CInt"]} -> "CInt"];Compile a program that uses the function:
cf = FunctionCompile[funcDec,
Function[Typed[n, "CInt"], Module[{ptr},
ptr = Typed[ToRawPointer[], "RawPointer"::["CInt"]];
LibraryFunction["addonePointer"][n, ptr];
FromRawPointer[ptr]
]]]cf[12]Represent a library function that populates a "CArray" with a sequence of square numbers:
funcDec = LibraryFunctionDeclaration["populateArray", "compilerDemoBase", {"CArray"::["CLong"], "CLong"} -> "CInt"];Compile a program that uses FromRawPointer to extract elements of the populated array:
cf = FunctionCompile[funcDec,
Function[Typed[n, "CLong"], Module[{arr},
arr = CreateTypeInstance["Managed"::["CArray"::["CLong"]], n];
LibraryFunction["populateArray"][arr, n];
Table[Cast[FromRawPointer[arr, i - 1], "MachineInteger"], {i, n}]
]]]cf[25]History
Text
Wolfram Research (2022), FromRawPointer, Wolfram Language function, https://reference.wolfram.com/language/ref/FromRawPointer.html.
CMS
Wolfram Language. 2022. "FromRawPointer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/FromRawPointer.html.
APA
Wolfram Language. (2022). FromRawPointer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FromRawPointer.html
BibTeX
@misc{reference.wolfram_2026_fromrawpointer, author="Wolfram Research", title="{FromRawPointer}", year="2022", howpublished="\url{https://reference.wolfram.com/language/ref/FromRawPointer.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_fromrawpointer, organization={Wolfram Research}, title={FromRawPointer}, year={2022}, url={https://reference.wolfram.com/language/ref/FromRawPointer.html}, note=[Accessed: 13-June-2026]}