Re: Issues with memcpy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Javier,

>I'm a bit confused, why is using 12 bytes if it's a char + 2 int's?

Probably (and I say that because I am making a presumption) because your system requires/recommends the int data types to be aligned on a 4 byte boundary.

So the compiler puts in padding bytes between the char and the int so that the structure will comply with your architecture's restrictions/recommendations.

Your print loop is displaying the pad bytes, which will contain uninitialized random data.

HTH,
--Eljay

PS:  You may want to change your code to printf("%02x ", buffer[a] & 0xFF); to avoid undesirable sign extension and make the code 8-bit platform agnostic regardless whether char is signed or unsigned under the covers.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux