I am doing a memcpy of clsf_ptr to upclsf
memcpy(&upclsf, &clsf_ptr, sizeof(struct classifier));
while debugging using gdb i checked the memory address of upclsf
when i did print &upclsf i got
(gdb) p &upclsf
$1 = (struct classifier **) 0xbffff184
when i did print upclsf i got
(gdb) p upclsf
$2 = (struct classifier *) 0x2e312e31
which is the address here i am not able to understand, here upclsf is an instance of the structure classifier
GDB disagrees —
upclsfis not astruct classifier, it is a pointer. Note that the two answers have different types. The first one (&upclsf) isstruct classifier **, the second one (upclsf) isstruct classifier *. Here is the memory layout:You want to change your
memcpyto:Or possibly:
Note that
memcpywill wantonly destroy data and is not type-safe! Therefore you have to be extra careful when you use it to ensure that the types you give it are correct. I suggest defining the following function:This will catch type errors. I make one of these for any structure I copy more than once or twice.