Unable to free const pointers in C
Posted
by lego69
on Stack Overflow
See other posts from Stack Overflow
or by lego69
Published on 2010-05-12T14:08:13Z
Indexed on
2010/05/12
14:24 UTC
Read the original article
Hit count: 252
Filed under:
c
How can I free a const char*
? I allocated new memory using malloc
, and when I'm trying to free it I always receive the error "incompatible pointer type"
The code that causes this is something like:
char* name="Arnold";
const char* str=(const char*)malloc(strlen(name)+1);
free(str); // error here
© Stack Overflow or respective owner