This is the mail archive of the gcc@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: memcpy to an unaligned address


>>>>> "Shaun" == Shaun Jackman <sjackman@gmail.com> writes:

 >> 2) Is there padding between the struct members to maintain their
 >> natural alignments (on the assumption that the struct's base
 >> address is aligned.)

 Shaun> There is no padding. The structure is defined as
 Shaun> __attribute__((packed)) to explicitly remove the padding. The
 Shaun> result is that gcc knows the unaligned four byte member is at
 Shaun> an offset of two bytes from the base of the struct, but uses a
 Shaun> four byte load at the unaligned address of base+2. I don't
 Shaun> expect...
 Shaun>		 p-> unaligned = n;
 Shaun> ... to work, ...

I would.  If you tell gcc that a thing is unaligned, it is responsible
for doing unaligned references to it.  That very definitely includes
direct references to the content in expressions.  And in general that
works.  Clearly there is a GCC bug here; GCC put the field at an
unaligned offset, but did not do unaligned references to it.

	  paul


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