in an effort to solve question #3367795 here on SO i have to cope with a number of subproblems. one of these is: in said algorithm (levenshtein distance), several arrays are allocated in memory and initialized with the lines
cdef char *m1 = <char *>calloc( blen + 2, sizeof( char ) )
cdef char *m2 = <char *>calloc( blen + 2, sizeof( char ) )
cdef char *m3 = <char *>malloc( ( blen + 2 ) * sizeof( char ) )
#.........................................................................
for i from 0 <= i <= blen:
m2[ i ] = i
<...snip...>
blen
here refers to the length of a Python bytes
variable. now as far as i understand the algorithm (see my original post for the full code) and as the code for the initialization of m2
clearly shows, these arrays are meant to hold integer numbers, not characters, so one would think the correct allocations should look like
cdef int *m3 = <int *>malloc( ( blen + 2 ) * sizeof( int ) )
and so on. can anyone with a background in C elucidate to me why char
is used? also, maybe more for people inclined to Cython, why is there a cast <char *>
? one would think that char *x = malloc( ... )
should suffice to define x
.