I would like to change the buffer
Then it's not const
.
the program hangs or simply does not work
It looks like a clear description of undefined behavior . I bet that to write in buffer
you had to do a constant pointer conversion to non-constant pointer; this can cause undefined behavior, try passing the buffer
as not constant:
int mifuncion(void * buffer){
/* mas codigo */
}
Another thing that could be happening (and that would also cause indefinite behavior) is that you screw up writing in buffer
, I see that mifuncion
does not receive size parameter so if you are passing a pointing pointer to a buffer of size X but you write Y (if Y> X) you could have this problem, to solve it it indicates what the writing limit is:
int mifuncion(void * buffer, int tamanyo_buffer){
/* mas codigo */
}
And use the tamanyo_buffer
parameter to write a maximum of that number of bytes.
But that does not help either, because the type void
has no size and consequently you can not do pointer arithmetic with it, so I bet that in addition to transforming bufer
so that it is not constant, you must transform it to a guy with size
int mifuncion(void * buffer, int tamanyo_buffer){
char *inicio = (char *)buffer;
/* mas codigo usando inicio en lugar de buffer */
}