I\'m trying to return the data pointer from the function parameter:
bool dosomething(char *data){
int datasize = 100;
data = (char *)malloc(datasize);
You're passing by value. dosomething
modifies its local copy of data
- the caller will never see that.
Use this:
bool dosomething(char **data){
int datasize = 100;
*data = (char *)malloc(datasize);
return 1;
}
char *data = NULL;
if(dosomething(&data)){
}
int changeme(int foobar) {
foobar = 42;
return 0;
}
int main(void) {
int quux = 0;
changeme(quux);
/* what do you expect `quux` to have now? */
}
It's the same thing with your snippet.
C passes everything by value.