-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 According to Gary V. Vaughan on 4/2/2007 4:37 PM: >> Cast the subscript to unsigned char before using it as index. >> Otherwise, on a system where char is signed, and its high bit is set, >> and you haven't adjusted the array range to allow for negative values, >> fun will ensue. > > If the table value for META-^A is held at element 128 of the array (since > the table was built assuming char* is unsigned by default), and we compile > on a host with signed chars, does the signed char value of META-^A still > become 128 when cast to unsigned char? Or does 2's complement come into > play and scramble the order of the negative signed char values when > casting them before doing a table lookup?
As long as the table is handled consistently (in other words, as long as ALL uses of characters as indices occur as unsigned char or within to_uchar), then META-^A (usually encoded as -128 in signed char) will always appear at the same index, regardless of whether that index is 128 (as it will be on 2's complement machine; the bulk of what exists today), or 255 (which is what (unsigned char) -128 might become on a 1's compliment machine, mostly theoretical). You only run into the bug that you were describing if you also reference the array based on a given integer encoding of characters. - -- Don't work too hard, make some time for fun as well! Eric Blake [EMAIL PROTECTED] -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (Cygwin) Comment: Public key at home.comcast.net/~ericblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGEcGX84KuGfSFAYARAhoWAKCL8gRMEWiFzkIkie/wR8vh64HOnQCgxoxz Rh5wXLvyWV4uQY5XFYErJBY= =p822 -----END PGP SIGNATURE----- _______________________________________________ Bug-m4 mailing list [email protected] http://lists.gnu.org/mailman/listinfo/bug-m4
