Hi guys.
Let's say I've got something like this:
struct Box{
//something
};
typedef struct Box* pBox;
void fun(pBox p);
int main(){
pBox p = NULL;
fun(p);
}
void fun(pBox p){
if(p == NULL) p = (pBox)malloc(si zeof(Box));
}
function fun recieves the address(which is NULL) and then allocates the memory for the Box; Let's say I cannot return the address of new allocated p and I can't also use that pointer p(from main) without passing it into a function.
Q: How can I make it that I could operate in function "fun" as I operate on orginal pointer p(from main), right now I'm just passing the address to my function but I can't change
the 'global' pointer p ;(.
I remember in pascal it's like:
"function(v ar pointer:[pointer to sth])"
and all is done.
How can I do it in C?
Any ideas?
Let's say I've got something like this:
struct Box{
//something
};
typedef struct Box* pBox;
void fun(pBox p);
int main(){
pBox p = NULL;
fun(p);
}
void fun(pBox p){
if(p == NULL) p = (pBox)malloc(si zeof(Box));
}
function fun recieves the address(which is NULL) and then allocates the memory for the Box; Let's say I cannot return the address of new allocated p and I can't also use that pointer p(from main) without passing it into a function.
Q: How can I make it that I could operate in function "fun" as I operate on orginal pointer p(from main), right now I'm just passing the address to my function but I can't change
the 'global' pointer p ;(.
I remember in pascal it's like:
"function(v ar pointer:[pointer to sth])"
and all is done.
How can I do it in C?
Any ideas?
Comment