boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

094-narrow-bitwise.c (511B)


      1 /* Bitwise on narrow types: char/short are sign-extended to int before op. */
      2 
      3 int main(int argc, char **argv) {
      4     /* (char)0xFF == -1; sign-extended -> 0xFFFFFFFF; & 0xAA -> 0xAA */
      5     char c = (char)0xFF;
      6     int r = c & 0xAA;
      7     if (r != 0xAA) return 1;
      8 
      9     /* unsigned char: zero-extends. */
     10     unsigned char u = 0xFF;
     11     int r2 = u & 0xAA;
     12     if (r2 != 0xAA) return 2;
     13 
     14     /* Shift on short: width is int. */
     15     short s = 1;
     16     int sh = s << 16;
     17     if (sh != 0x10000) return 3;
     18     return 0;
     19 }