Here's an example:
%load_ext cython
%%cython -a
from libc.stdlib cimport malloc
def main():
cdef int *qux = <int*>malloc(3*sizeof(int))
qux[0] = 4
qux[1] = 5
qux[2] = 6
qux[3] = 7
print(qux[0])
print(qux[3])
I was expecting the first print statement to work, but for either qux[3] = 7
to fail, or print(qux[3])
to print garbage. However, it correctly prints 7
.
Why is this? Does it not matter how much I malloc
to qux
?