[ale] Copy a Structure - A C Question

Fletch fletch at phydeaux.org
Fri Jun 14 07:41:08 EDT 2002


>>>>> "Terry" == Terry Lee Tucker <terry at esc1.com> writes:


[...]

    Terry> pointers to other structures. Since this is a structure, is
    Terry> all the allocated memory for the structure in one
    Terry> contiguous chunk? If so, could I then use something like
    Terry> memcpy to do the job?


        Not unless the components of your structure were declared
inline rather than as pointers.  There's probably very little chance
that it's contiguous. The best thing to do is define a clone_foo()
function for each of the various component structures that returns a
new copy.  Then build a master clone_bar() that copies the containing
structure piece by piece using strcpy() and the various clone_foo()'s.


-- 
Fletch                | "If you find my answers frightening,       __`'/|
fletch at phydeaux.org   |  Vincent, you should cease askin'          \ o.O'
770 933-0600 x211(w)  |  scary questions." -- Jules                =(___)=
770 294-0820 (m)      |                                               U

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list