This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: Issues with memcpy
- From: Matthew Jones <matthewjones at vw1600e dot org dot uk>
- To: gcc-help at gcc dot gnu dot org
- Cc: Javier at vw1600e dot org dot uk, Valencia at vw1600e dot org dot uk
- Date: Wed, 27 Apr 2005 14:24:19 +0100
- Subject: RE: Issues with memcpy
- References: <1114539045.7450.ezmlm@gcc.gnu.org>
> 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/