boot2

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

028-cast.c (447B)


      1 /* tests/cc-e2e/28-cast.c — narrowing cast with sign-extend on re-widen.
      2  * Split from 01-kitchen-sink. */
      3 
      4 int test_cast(void) {
      5     int a = 300;
      6     int b = (int)(char)a;           /* (char)300 = 44 (sign-extends back to int) */
      7     int c = (int)(short)a;          /* (short)300 = 300 (fits in 16 bits) */
      8     return b + c;                   /* 344 */
      9 }
     10 
     11 int main(int argc, char **argv) {
     12     if (test_cast() != 344) return 1;
     13     return 0;
     14 }