|
|
1.1 root 1: /* The Plum Hall Validation Suite for C
2: * Unpublished copyright (c) 1986-1991, Chiron Systems Inc and Plum Hall Inc.
3: * VERSION: 4
4: * DATE: 1993-01-01
5: * The "ANSI" mode of this suite corresponds to official ANSI C, X3.159-1989.
6: * As per your license agreement, your distribution is not to be moved or copied outside the Designated Site
7: * without specific permission from Plum Hall Inc.
8: */
9:
10: /*
11: * BITFIELDS - make sure that all operators work with bitfields.
12: * Called at or about line 48 in c3_5.
13: */
14:
15: #include "flags.h"
16: #ifndef SKIP35B
17: #include "defs.h"
18:
19: static int SideEffect = 0;
20: struct fields
21: {
22: unsigned x1:1;
23: unsigned x2:2;
24: unsigned x3:3;
25: unsigned :1; /* just because it can be done */
26: unsigned x4:4;
27: };
28:
29: void bitfields()
30: {
31: struct fields b, b2, *p = &b2, *bf();
32:
33: Filename = "c35b.c";
34: b.x2 = 2;
35: p->x3 = 7;
36:
37: iequals(__LINE__, b.x2++, 2);
38: iequals(__LINE__, b.x2--, 3);
39: iequals(__LINE__, ++b.x2, 3);
40: iequals(__LINE__, --b.x2, 2);
41: /* &bitfield is illegal */
42: #if ANSI
43: iequals(__LINE__, +b.x2, 2);
44: #endif
45: iequals(__LINE__, -b.x2, -2);
46: iequals(__LINE__, ~b.x2, ~2);
47: iequals(__LINE__, !b.x2, 0);
48: dequals(__LINE__, (double)b.x2, 2.0);
49: iequals(__LINE__, b.x2*p->x3, 14);
50: iequals(__LINE__, p->x3/b.x2, 3);
51:
52:
53: iequals(__LINE__, p->x3%b.x2, 1);
54: iequals(__LINE__, p->x3+b.x2, 9);
55: iequals(__LINE__, p->x3-b.x2, 5);
56: iequals(__LINE__, p->x3>>b.x2, 7>>2);
57: iequals(__LINE__, p->x3<<b.x2, 7<<2);
58: iequals(__LINE__, p->x3>b.x2, 1);
59: iequals(__LINE__, p->x3<b.x2, 0);
60: iequals(__LINE__, p->x3>=b.x2, 1);
61: iequals(__LINE__, p->x3<=b.x2, 0);
62: iequals(__LINE__, p->x3==b.x2, 0);
63: iequals(__LINE__, p->x3!=b.x2, 1);
64: iequals(__LINE__, p->x3&b.x2, 2);
65: iequals(__LINE__, p->x3^b.x2, 5);
66: iequals(__LINE__, p->x3|b.x2, 7);
67: iequals(__LINE__, p->x3&&b.x2, 1);
68: iequals(__LINE__, p->x3||b.x2, 1);
69: iequals(__LINE__, p->x3?b.x2:0, 2);
70:
71: /* the first two are tricky -- make sure that the expression value is
72: * the same as the left hand side after assignment (wraparound occurs).
73: */
74: iequals(__LINE__, p->x3=15, 7);
75: iequals(__LINE__, p->x3*=b.x2, 6);
76: iequals(__LINE__, p->x3/=b.x2, 3);
77: iequals(__LINE__, p->x3%=b.x2, 1);
78: iequals(__LINE__, p->x3+=b.x2, 3);
79: iequals(__LINE__, p->x3-=b.x2, 1);
80: iequals(__LINE__, p->x3<<=b.x2, 4);
81: iequals(__LINE__, p->x3>>=b.x2, 1);
82: b.x2 = 3;
83: iequals(__LINE__, p->x3&=b.x2, 1);
84: iequals(__LINE__, p->x3^=b.x2, 2);
85: iequals(__LINE__, p->x3|=b.x2, 3);
86: iequals(__LINE__, (p->x3,b.x2), 3);
87:
88: /* check for incorrect side effects */
89: bf()->x3 = 3;
90: bf()->x2 = 2;
91: iequals(__LINE__, bf()->x3 *= bf()->x2, 6);
92: iequals(__LINE__, bf()->x3 /= bf()->x2, 3);
93: iequals(__LINE__, bf()->x3 %= bf()->x2, 1);
94: iequals(__LINE__, bf()->x3 += (SideEffect++, bf())->x2, 3);
95: iequals(__LINE__, bf()->x3 -= (SideEffect++, bf())->x2, 1);
96: iequals(__LINE__, (SideEffect++, bf())->x3 <<= bf()->x2, 4);
97: iequals(__LINE__, (SideEffect++, bf())->x3 >>= bf()->x2, 1);
98: iequals(__LINE__, SideEffect, 20);
99: }
100:
101:
102:
103:
104: struct fields *bf()
105: {
106: static struct fields f;
107: ++SideEffect;
108: return(&f);
109: }
110:
111: #else /* if SKIP35B */
112: void bitfields() { pr_skip("bitfields (c35b): SKIPPED ENTIRELY\n"); }
113: #endif /* SKIP35B */
114:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.