[ale] Copy a Structure - A C Question
Terry Lee Tucker
terry at esc1.com
Fri Jun 14 10:36:09 EDT 2002
Thanks for the response. All the strings in the structure are declared
as character pointers and allocated dynamically. Yet, aparently, both
memcpy and bcopy work corrctly. Am I setting myself up for some kind of
strange core dump later on?
Here is the structure layout:
typedef struct _field
{
Widget iName; /* detail screen widget ID */
Widget sName; /* search screen widget ID */
int length; /* text field max length */
int dataType; /* escNUMERIC, escSTRING,
escBOOLEAN, escDATE */
int location; /* stores browse cell location of
data */
char *format; /* format string */
char *dbName; /* field name in the database */
char *value; /* pointer to input data void of
formatting */
char *operator; /* the operator to use in "WHERE"
clause */
char *function; /* the address of a function */
char *help; /* points to field level help string */
Boolean browse; /* tell esql.c whether field is on
browser */
Boolean focusFlag; /* set to True if field received focus */
Boolean trackFlag; /* prevent modified flag being set when
GetFocusCB () applies
field formating */
Boolean isNegative; /* True if a negative number */
Boolean modified; /* set to True if field modified */
Boolean search; /* defines a search screen NODE as
well */
Boolean searchOnly; /* defines a search only NODE */
Boolean create; /* write to db during create but no
edit */
Boolean editable; /* allow edits of this field? */
Boolean create_edit; /* allow edits during create */
Boolean validated; /* prevents infinite loop in LoseFocusCB */
Boolean valid; /* true if data entry is valid */
struct _field *sister; /* point to my sister */
struct _field *next; /* point to the next struct in the
list */
} Field;
Fletch wrote:
>>>>>>"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.
>
>
--
Sparta, NC 28675 USA
336.372.6812
http://www.esc1.com
I hate Micro$oft. Any questions?
---
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