C
CBFalconer
Keith said:.... snip ...
Interesting. I just tried it with a number of compilers, and they
all got it right (everything promotes to signed).
Now start playing with the defines in this variant on Jacks test:
#include <stdio.h>
struct nu {
unsigned uc: 8;
unsigned us: 16;
};
#define DELTA 32900 /* 5 or 32900 */
#define INIT -1 /* 0 or -1 */
int main(void)
{
unsigned char uc = INIT;
unsigned short us = INIT;
struct nu nu = { INIT, INIT };
if ((uc - DELTA) < 0) puts("unsigned char ==> signed");
else puts("unsigned char ==> unsigned");
if ((nu.uc - DELTA) < 0) puts("unsigned :8 ==> signed");
else puts("unsigned :8 ==> unsigned");
if ((us - DELTA) < 0) puts("unsigned short ==> signed");
else puts("unsigned short ==> unsigned");
if ((nu.us - DELTA) < 0) puts("unsigned :16 ==> signed");
else puts("unsigned :16 ==> unsigned");
return 0;
}