History

Tests on left-shift type.

Vincent Lefevre committed 14 years ago

Commit 09b98a41 parent d54e24c3 files · +55 −1Browse files

Unified · Split

3 files
  1. tests2/55_lshift_type.c +52 −0
  2. tests2/55_lshift_type.expect +1 −0
  3. tests2/Makefile +2 −1
tests2/55_lshift_type.c+52−0
@@ -0,0 +1,52 @@
1/* $Id: lshift-type.c 53089 2012-07-06 11:18:26Z vinc17/ypig $
2
3Tests on left-shift type, written by Vincent Lefevre <vincent@vinc17.net>.
4
5ISO C99 TC3 says: [6.5.7#3] "The integer promotions are performed on
6each of the operands. The type of the result is that of the promoted
7left 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
35static int debug, nfailed = 0;
36
37static 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
45int 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}
tests2/55_lshift_type.expect+1−0
@@ -0,0 +1 @@
10 test(s) failed
tests2/Makefile+2−1
@@ -61,7 +61,8 @@ TESTS= 00_assignment.test \ · 60 unmodified lines
61 50_logical_second_arg.test \61 50_logical_second_arg.test \
62 51_static.test \62 51_static.test \
63 52_unnamed_enum.test \63 52_unnamed_enum.test \
64 54_goto.test64 54_goto.test \
65 55_lshift_type.test
65 66
66 # 30_hanoi.test \ # seg fault in the code, gcc as well67 # 30_hanoi.test \ # seg fault in the code, gcc as well
67 # 34_array_assignment.test \ # array assignment is not in C standard68 # 34_array_assignment.test \ # array assignment is not in C standard

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t