Possible bug

David Sheckler david.sheckler@dat.com
Wed May 12 14:03:00 GMT 1999


Or a question of behaviour... While porting an old application from
Solaris 2.4 to Linux/egcs, I had a problem reading in an index. The
index was 2 bytes and read into a "char CharacterIndex[2];" then cast
into a short as follows: 
ShortIntegerIndex = *(short *)CharacterIndex; So, if my original value
in CharacterIndex is 0x003b. It is cast into ShortIntegerIndex as
0x00003b00. I assume the = operator copied the value in from left to
right, where as the sparc compiler copied it right to left filling the
rest with zeros, so it had 0x0000003b for ShortIntegerIndex. The
original code assumed a 2 byte short. I would think the prefered
behaviour is for the complier to copy it "right to left" filling the
rest with zeros when the destination is numeric.

#gcc --version
egcs-2.91.60

Using the SUSE linux 6.0 distribution.

If this was of no help at all and I'm full of shit, please don't
hesitate to tell me so.
-Dave Sheckler


More information about the Gcc-bugs mailing list