Skip to content

Commit 15d6a92

Browse files
committed
Added text on signed/unsigned chars
1 parent 40f806f commit 15d6a92

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ Check the `README.md` in directory `test` for more information.
4444

4545
Also see http://www.mapcode.com for background and reference materials.
4646

47+
## Compilers: Signed and Unsigned `char`
48+
49+
The library expects the type `char` to be `signed char` by default. If your compiler
50+
uses `unsigned char` by default (such as for ARM or PowerPC), please add the correct
51+
compiler switch to change this behavior to `signed char`.
52+
53+
The unit tests in `test` will test the correct settings of the compiler and will
54+
fail if you've compiled the library with incorrect settings.
4755

4856
## A Real-Life Example, The 'mapcode' Codec Tool: `utility/`
4957

test/unittest.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,16 @@ static int testEnvironment(void) {
14651465
printf("sizeof(char)=%ld, sizeof(UWORD)=%ld, sizeof(int)=%ld, sizeof(long int)=%ld\n",
14661466
sizeof(char), sizeof(UWORD), sizeof(int), sizeof(long int));
14671467

1468+
// Check signed/unsigned character.
1469+
char t = (char) (-1);
1470+
if ((int) t == -1) {
1471+
printf("char is signed\n");
1472+
} else {
1473+
printf("char is unsigned\n");
1474+
foundError();
1475+
printf("*** ERROR *** Compiled with 'unsigned char'; please recompile to use 'signed char' by default.\n");
1476+
}
1477+
14681478
// Check size of UWORD.
14691479
nrTests++;
14701480
if (sizeOfWord != 2) {

0 commit comments

Comments
 (0)