I'm curious as to why the following trivial example does not work:
file: new.c
#include "new.h"
void test( char * x )
{
free( x );
}
file: new.h
void test( char * );
file: weird.c
#include "new.h"
int main( void )
{
char * strange = "this is strange";
test( strange );
return 0;
}
matt@Ragnarok ~/Code/C $ gcc -c new.c
matt@Ragnarok ~/Code/C $ gcc -o weird weird.c new.o
matt@Ragnarok ~/Code/C $ ./weird
*** glibc detected *** ./weird: free(): invalid pointer: 0x0804847c ***
What would I have to do if I wanted to do something like this? I get the same kind of problem if I do x[3] = 'c'; or *( x + 3 ) = 'c'.
I think it's just some fundamental misunderstanding and someone can set me straight. Thanks.