Correct use of memcpy in C -
i attempting copy content of error object deque, when check copied content, not correct.
typedef struct er_object { uint8 error_type; union { uint32 number; char *message; } error; } er_object; void er_copy(de_list *deque, er_object *object) { er_object *marker; marker = er_get_first_object(deque); memcpy(object, marker, sizeof(*marker)); }
everything , including function er_get_first_object
works intended, ie can examine content of marker , correct. leads me believe problem lies memcpy.
if create second pointer er_object called marker2, , use memcpy copy content of marker marker2, works fine. when attempt copy content of marker external object error occurs.
would kind point out doing wrong?
unfortunately, posted code correct.
i "unfortunately" because means problem somewhere else in program. suggest using additional tools, such mudflap , valgrind.
- if using gcc, compile
-fmudflap
. requires mudflap libraries installed. - run valgrind.
the tools overlap in purpose somewhat, there errors 1 of 2 tools catch.
Comments
Post a Comment