W
whisper
This is interesting, but I dont understand your response (sorry, I am
just learning).
What do you mean by "meaningless global identifiers" ?
I had the same question regarding returning the entire struct in Eric's
example
He wrote:
struct matrix create_set(int m, int n) {
struct matrix set;
set.rows = m;
/* code snipped */
}
return set;
}
Situation A:
Now when this function is called, storage is allocated for the new
structure
and a copy of it is passed to the calling function, and the original
storage is deallocated.
Is my understanding of the process correct ?
Situation B:
So why not allocate as he has done and return &set (a pointer to the
memory allocated).
How does compare to situation A ?
In particular, what is automatic storage ?
In situation A and B, isn't the memory allocated on the program stack
the same way -
the only difference being that one has a shorter lifespan than the
other ?
Is it just returning a pointer to the malloc-ed area ensure that the
allocated storage remains
in play for the rest of the life of the program ?
I appreciate everybody's responses in helping this student learn.
just learning).
What do you mean by "meaningless global identifiers" ?
I had the same question regarding returning the entire struct in Eric's
example
He wrote:
struct matrix create_set(int m, int n) {
struct matrix set;
set.rows = m;
/* code snipped */
}
return set;
}
Situation A:
Now when this function is called, storage is allocated for the new
structure
and a copy of it is passed to the calling function, and the original
storage is deallocated.
Is my understanding of the process correct ?
Situation B:
So why not allocate as he has done and return &set (a pointer to the
memory allocated).
How does compare to situation A ?
In particular, what is automatic storage ?
In situation A and B, isn't the memory allocated on the program stack
the same way -
the only difference being that one has a shorter lifespan than the
other ?
Is it just returning a pointer to the malloc-ed area ensure that the
allocated storage remains
in play for the rest of the life of the program ?
I appreciate everybody's responses in helping this student learn.