On this page
ctypes.cast
Prev: ctypes.c_longdouble_complex | Up: ctypes | Next: ctypes.create_string_buffer
Rel: ctypes.addressof, ctypes.alignment, ctypes.ArgumentError, ctypes.Array
Ref: docs.python.org — ctypes.cast
Tags: #public #python3 #stdlib #ctypes
Import
import ctypes
from ctypes import cast
Signature & Overview
ctypes.cast(obj, typ)
ctypes.cast() function.
Usage
import ctypes
arr = (ctypes.c_int * 2)(10, 20)
p = ctypes.cast(arr, ctypes.POINTER(ctypes.c_int))
assert p[0] == 10 and p[1] == 20
Gotchas
- Does not validate bounds or alignment: Keep the original object (
arr) alive while using the cast pointer.
REPL Inspect
from ctypes import cast
help(cast)
Linked from
Related notes
- tuts/python3/stdlib_module/ctypes/c_longdouble_complex Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/create_string_buffer Linked here; links to this page; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ctypes/addressof Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/alignment Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/ArgumentError Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/Array Linked here; shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/BigEndianStructure shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/BigEndianUnion shared tags: #ctypes, #stdlib
- tuts/python3/stdlib_module/ctypes/byref shared tags: #ctypes, #stdlib