00200.c (1532B)
1 /* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $ 2 3 Tests on left-shift type, written by Vincent Lefevre <vincent@vinc17.net>. 4 5 ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on 6 each of the operands. The type of the result is that of the promoted 7 left operand." 8 */ 9 10 #include <stdio.h> 11 12 #define PTYPE(M) ((M) < 0 || -(M) < 0 ? -1 : 1) * (int) sizeof((M)+0) 13 #define CHECK(X,T) check(#X, PTYPE(X), PTYPE((X) << (T) 1)) 14 #define TEST1(X,T) do { CHECK(X,T); CHECK(X,unsigned T); } while (0) 15 #define TEST2(X) \ 16 do \ 17 { \ 18 TEST1((X),short); \ 19 TEST1((X),int); \ 20 TEST1((X),long); \ 21 TEST1((X),long long); \ 22 } \ 23 while (0) 24 #define TEST3(X,T) do { TEST2((T)(X)); TEST2((unsigned T)(X)); } while (0) 25 #define TEST4(X) \ 26 do \ 27 { \ 28 TEST3((X),short); \ 29 TEST3((X),int); \ 30 TEST3((X),long); \ 31 TEST3((X),long long); \ 32 } \ 33 while (0) 34 35 static int debug, nfailed = 0; 36 37 static void check (const char *s, int arg1, int shift) 38 { 39 int failed = arg1 != shift; 40 if (debug || failed) 41 printf ("%s %d %d\n", s, arg1, shift); 42 nfailed += failed; 43 } 44 45 int main (int argc, char **argv) 46 { 47 debug = argc > 1; 48 TEST4(1); 49 TEST4(-1); 50 printf ("%d test(s) failed\n", nfailed); 51 return nfailed != 0; 52 }