// Test a C23-compliant implementation of deserialization of a 16-bit // signed value. Tested on amd64 (char is signed char) and ARM EABI5 // emulated with QEMU (char is unsigned char). #include typedef struct { char hh, lh; int expected; } testcase; testcase cases[] = { { 0, 0, 0 }, { 0, 1, 1 }, { 1, 0, 256 }, { 255, 255, -1 }, { 128, 0, -32768 }, { 132, 245, -31499 }, { 80, 224, 20704 }, }; int decode(char hh, char lh) { return (unsigned char)lh | ((int)(signed char)hh << 8); } int main() { int failures = 0; for (int i = 0; i != sizeof cases / sizeof(testcase); i++) { testcase t = cases[i]; int result = decode(t.hh, t.lh); if (result != t.expected) { failures++; fprintf(stderr, "decode(%d, %d) == %d rather than expected %d\n", t.hh, t.lh, result, t.expected); } } return failures; }