CPointer
CPointer<T> is the type in Cangjie that represents C pointers, corresponding to T* in C. The generic parameter T must satisfy the CType constraint, meaning it has a memory layout compatible with C.
You can create a null pointer using CPointer<T>() and check if a pointer is null using the isNull() method. Cangjie supports pointer arithmetic, allowing you to offset pointers using + and -. Pointer type conversion uses the CPointer<NewT>(oldPtr) form.
Reading and writing data through pointers are unsafe operations and must be performed within an unsafe block. Use read() to read the value pointed to, and write() to write a value. The code on the right demonstrates common operations such as memory allocation, type conversion, reading and writing data, and pointer arithmetic.
CPointer is unsafe; invalid pointers can lead to undefined behavior.Try modifying the code to allocate memory for a Point3D struct, write data to it, then read it back and print it.