Unsigned char logical operations
Duane Ellis
duane_ellis@franklin.com
Tue Jun 20 16:48:00 GMT 2000
GCC 2.95.2, configured as follows:
Linux, Red Hat 6.1 (Intel i686)
tar xfz gcc-2.95.2.tar.gz
cd gcc-2.95.2
./configure [see output of config.status below]
make
make install
cat config.status, shows this:
./configure --with-gcc-version-trigger=/nbu/ereader/duane/gcc-2.95.2/gcc/version.c --host=i686-pc-linux-gnu --prefix=/nbu/ereader/duane/install --norecursion
Any questions, please contact me.
Thanks,
--Duane.
This small piece of code reports the wrong values.
--------------------------------------------------
/* Assumes ASCII char set, */
typedef unsigned char U8;
#define MY_BIT 0x08
U8 data[ 16 ];
char string[10];
static void
do_char( char *str, int i, int flag, int ch )
{
if( flag ){
str[i] = ch + 0x20; /* capitalize it */
} else {
str[i] = ch;
}
}
int
main( int argc, char **argv )
{
int indx;
int x;
/* BUG BUG BUG BUG */
x = 0;
indx = 3;
data[ indx ] = 0x0ff;
do_char( string, x, data[ indx ] & MY_BIT, 'd' );
string[1] = 0;
printf("Result is: %s\n", string );
/* Should print 'D' */
/* THIS VERSION IS OK */
x = 0;
indx = 3;
data[ indx ] = 0x000;
do_char( string, x, data[ indx ] & MY_BIT, 'd' );
string[1] = 0;
printf("Result is: %s\n", string );
/* should print 'd' */
}
More information about the Gcc-bugs
mailing list