G
Generic Usenet Account
Is it okay to return a local datastructure (something of type struct)
from a function, as long as it does not have any pointer fields? I
think it is a bad idea, but one of my colleagues does not seem to think
so. According to my colleague, if the data structure does not "deep
copy" issues, it is perfectly okay to return a local variable. This is
because at the point of invocation, a copy of the data structure is
made.
In all fairness to my colleague, he does admit that it is inefficient
to return datastructures from functions, but he passionately belives in
the legitimacy of returning stack data structures without "deep copy"
issues (i.e. without any pointer fields).
Thanks,
Keerti
from a function, as long as it does not have any pointer fields? I
think it is a bad idea, but one of my colleagues does not seem to think
so. According to my colleague, if the data structure does not "deep
copy" issues, it is perfectly okay to return a local variable. This is
because at the point of invocation, a copy of the data structure is
made.
In all fairness to my colleague, he does admit that it is inefficient
to return datastructures from functions, but he passionately belives in
the legitimacy of returning stack data structures without "deep copy"
issues (i.e. without any pointer fields).
Thanks,
Keerti