This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Issues with memcpy


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]