RE: Issues with memcpy

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

 



> Brian Budge wrote:
>
> >Could be my imagination, but are you assuming the size of your struct
> >is 9 bytes?  This is most likely a false assumption.  Try using
> >sizeof(t_st) instead.  Likely it's 12 bytes.
> >
>
> I'm a bit confused, why is using 12 bytes if it's a char + 2 int's?
> I think i'm not understanding something.

If you initialise your ints to a full 4 byte value, such as 0x11223344
you will get a clearer picture of what is happening. Most C compilers
align N word values to an N word boundary. Hence you probably have 3
bytes of padding between the char and the first int. These pad values
are picking up whatever is in memory at that point. They seem to have
their top bits set, so C is treating them as negative numbers and
printf is sign extending the value to a full 32 bits, because you are
using %x which expects an integer argument. If you use %c, or %2.2x
the bytes will look more as you expect.

--
Matthew JONES
http://www.tandbergtv.com/


[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