[Bug c/18287] Unaligned access to fields inside packed records
wintermute101 at wp dot pl
gcc-bugzilla@gcc.gnu.org
Thu Nov 4 16:54:00 GMT 2004
------- Additional Comments From wintermute101 at wp dot pl 2004-11-04 16:54 -------
I write here cause it's simmilar situation as reported here but I have no data
about other gcc versions than 3.3.2.
I have following:
/////////////////
define _aligned(n) __attribute__((aligned(n), packed))
struct CzazPort {
unsigned short number;
unsigned long speed;
unsigned long protocol;
unsigned long mode;
unsigned short timeout;
unsigned short loglevel;
unsigned short timerid;
} _aligned(2);
struct CzazPort tmp;
sscanf( data, "%lu", &tmp.speed );
/////////////////////
data="9600"
before sscanf (content of tmp)
00:01:00:00:96:00:52:54:55:00:38:4e:31:00:03:e8:00:04:2b:67
after sscanf
00:00:25:80:96:00:52:54:55:00:38:4e:31:00:03:e8:00:04:2b:67
9600 in hex -> 0x2580
it was compiled for MOXA UC7420
the same program compiled for i686 works fine
this MOXA has XScale Intel prcessor working in big-endian. I guess this is the
problem (big-endian).
sscanf is just example from source. The same occurs when I relpace sscanf with
(*(&tmp.speed)) = 9600;
but
tmp.speed=9600;
works fine.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18287
More information about the Gcc-bugs
mailing list