Author: Robert Hyatt
Date: 19:42:27 05/10/03
Go up one level in this thread
On May 10, 2003 at 20:31:23, Gareth McCaughan wrote: >Robert Hyatt wrote: > >>>>They have to be aligned left-to-right. IE from will be the MSbyte, piece will >>>>be the LSbyte. >>> >>>No. >> >>left-to-right means "ascending address order"... > >If that's what you meant by it, then that bit was correct. >But "from will be the MSbyte, piece will be the LSbyte" >is guaranteed only if you know the architecture the >thing is being compiled for. Ascending address order >needn't mean most significant byte first. > In the context given, my answer is correct. He put four chars into a struct. The first char will definitely be the "MSB" which is the left-most byte or the byte with the lowest memory address. The second char will follow sequentially... There can be no exception to that. byte 0 1 2 3 really don't apply to endianness... they _must_ be put into memory into ascending addresses. >In fact, on ia32 systems it's exactly the other way around, >so if Zach's code is going to run on a PC then "from" will >be the least significant byte and "piece" the most. Only if you load the entire thing at one "gulp" from something like mov eax, struct_addr. However, if you do the more common mov al, struct_addr you will get the first struct entry, one byte long. mov al, struct_addr+1 will get the second struct entry... > >Well, strictly even that isn't *guaranteed*, because: > >>>There may be padding anywhere within the structure, including >>>between those single-byte fields. > >Not that this is likely to be a problem in practice, in this >particular case. I'm not aware of padding between chars. It would break _everything_. > >-- >g
This page took 0.01 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.