c - Strange behavior of memcpy/memmove -


i have problem memcpy/memmove change pointer of struct foo foo, neither src nor destination of function. here gdb outputs:

before memmove(y,y_temp,size_y);:

(gdb) p y $38 = 0xbff7a2e0 (gdb) p y_temp $39 = (float *) 0x815ea20 (gdb) p foo $40 = (foo *) 0x81d4e90 

and after:

(gdb) p y_temp $41 = (float *) 0x343434 (gdb) p y  $42 = 0x343434  (gdb) p foo $43 = (foo *) 0x343434 

here definitions of variables:

foo *foo; float y[nsamples]; float size_y = nsamples*sizeof(y); float* y_temp = (float*) malloc(size_y); 

i know, not bug memcpy/move, looking tipp, programming error on side have caused it.

thanks

size_t size_y = sizeof(y); 

sizeof(y) gives size of whole array, , type should size_t.

if this, y , memory y_temp points same size. should make sure you're moving in right direction. right now, y destination. also, if source , destination don't overlap (which won't here), use memcpy.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -