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


>I'm a bit confused, why is using 12 bytes if it's a char + 2 int's?
Because the compiler likes to keep members of the struct aligned I think.

As for the strange output - you've created the struct on the 
stack, so you get your piece of memory but importantly it's uninitialised.
So you end up with whatever was lying around on the stack - ie junk.
If 0xfffffffa is confusing this is the represention of a negative
number - but it is still only a byte. Maybe you just need to bzero
the struct or change the declaration: t_st mystruct = {0};


-----Original Message-----
From: Javier Valencia [mailto:jvalencia@log01.org]
Sent: 27 April 2005 14:04
To: gcc-help@gcc.gnu.org
Subject: Re: Issues with memcpy


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.
>
>  Brian
>
>  
>

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.

I've redone using sizeof(t_st) in all points and this is the output:

tigre@enigma collector $ gcc pro.c
tigre@enigma collector $ ./a.out
5 0 0 0 5 0 0 0 5 0 0 0

tigre@enigma collector $ gcc pro2.c
tigre@enigma collector $ ./a.out
5 fffffffa ffffffff ffffffbf 5 0 0 0 5 0 0 0
5 fffffffa ffffffff ffffffbf 5 0 0 0 5 0 0 0

It have changed a bit, but strange things continue happening in pro2.c


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]