V61%DHDURZ1.BITNET@cunyvm.cuny.edu (Ronald Lamprecht) (06/13/89)
The ACK compiler (ST) doesn't apply (unsigned char) casts on char variables :
test()
{
char ch;
unsigned word;
word = (unsigned char) ch;
}
Will be compiled with -O -S options to:
.sect .text;.sect .rom;.sect .data;.sect .bss
.extern _test
.sect .text
_test:
link a6,#-4
!Local -4 into d7
move.l d7,-(sp)
move.b -1(a6),d0
ext.w d0
move.w d0, d7
move.l (sp)+,d7
unlk a6
rts
The char byte in d0 is extended with sign to a word (integer) ! I don't know
a general solution for this problem (besides a new compiler), but sometimes
an appropriated cast can help:
char str[]="hello";
test()
{
char *ptr;
unsigned int word;
word = *((unsigned char *)ptr);
}
will be compiled correctly to:
.sect .text;.sect .rom;.sect .data;.sect .bss
.extern _str
.sect .data
_str:
.data2 26725
.data2 27756
.extern _test
.data2 28416
.sect .text
_test:
link a6,#-6
!Local -6 into d7
!Local -4 into a5
move.l d7,-(sp)
move.l a5,-(sp)
clr.w -(sp)
move.b (a5),1(sp)
move.w (sp)+,d7
move.l (sp)+,a5
move.l (sp)+,d7
unlk a6
rts
Bitnet: V61@DHDURZ1 Ronald Lamprecht
UUCP: ...!unido!DHDURZ1.bitnet!V61 Theoretische Physik
ARPAnet: V61%DHDURZ1.BITNET@CUNYVM.CUNY.EDU (Heidelberg, West Germany)