|
|
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: #include "flags.h" ! 11: #ifndef SKIP34 ! 12: /* ! 13: * 3.4 - Constant expressions ! 14: */ ! 15: ! 16: #include "defs.h" ! 17: ! 18: ! 19: #if ANSI ! 20: static int i1 = +1; ! 21: static int i4 = !4; ! 22: static int i13 = 1 && 3; ! 23: static int i14 = 0 || 3; ! 24: #else ! 25: static int i1 = 1; ! 26: static int i4 = 0; ! 27: static int i13 = 1; ! 28: static int i14 = 1; ! 29: #endif ! 30: ! 31: static int i2 = -2; ! 32: static int i3 = ~3; ! 33: static int i5 = ((((((2*5) / 2) % 3) + 1) - 2) << 2) >> 2 ; ! 34: static int i6 = 4 < 5; ! 35: static int i7 = 4 > 5; ! 36: static int i8 = 4 <= 5; ! 37: static int i9 = 4 >= 5; ! 38: static int i10 = 4 == 5; ! 39: static int i11 = 4 != 5; ! 40: static int i12 = ((1 & 3) ^ 2) | 4; ! 41: static int i15 = 1 ? 1 : 2; ! 42: ! 43: static double d1 = 1.3; ! 44: static double d2 = (double)1; ! 45: ! 46: static char array[] = "abcd"; ! 47: static char *pc1 = array; ! 48: static char *pc2 = array + (1 + 3 * 2) / 7; ! 49: static char *pc3 = array - (-2 *(1 + 3 * 2)) / 7; ! 50: static char *pc4 = &array[3]; ! 51: ! 52: ! 53: static struct b { /* 3.4 (cont.) */ ! 54: int i; ! 55: unsigned int a : (1 + 3 * 2) / 7; ! 56: unsigned int b : (1 + 3 * 2) / 7; ! 57: } b, *pb = &b; ! 58: ! 59: #if ANSI8712 ! 60: static int *pi1 = &b.i; ! 61: static int *pi2 = &(&b)->i; ! 62: static int *pi3 = (int *)&b; ! 63: static int i16 = 1 || 2/0; ! 64: #endif ! 65: ! 66: #if (V7 || ANSI) ! 67: static enum { e2 = (4 + 3 * 2) / 5, e1 = (1 + 3 * 2) / 7} e; ! 68: #endif ! 69: ! 70: static char carray[4 + 3 * 2]; ! 71: ! 72: void c3_4() ! 73: { ! 74: int count, i; ! 75: static void (*pf)() = c3_4; ! 76: ! 77: Filename = "c34.c"; ! 78: ! 79: /* check out constant expressions from initializers */ ! 80: #if ANSI ! 81: iequals(__LINE__, i1, 1); ! 82: #endif ! 83: iequals(__LINE__, i2, -2); ! 84: iequals(__LINE__, i3, ~3); ! 85: iequals(__LINE__, i4, 0); ! 86: iequals(__LINE__, i5, 1); ! 87: iequals(__LINE__, i6, 1); ! 88: iequals(__LINE__, i7, 0); ! 89: iequals(__LINE__, i8, 1); ! 90: iequals(__LINE__, i9, 0); ! 91: iequals(__LINE__, i10, 0); ! 92: iequals(__LINE__, i11, 1); ! 93: iequals(__LINE__, i12, 7); ! 94: iequals(__LINE__, i13, 1); ! 95: iequals(__LINE__, i14, 1); ! 96: iequals(__LINE__, i15, 1); ! 97: ! 98: iequals(__LINE__, *pc1, 'a'); ! 99: iequals(__LINE__, *pc2, 'b'); ! 100: iequals(__LINE__, *pc3, 'c'); ! 101: iequals(__LINE__, *pc4, 'd'); ! 102: ! 103: dequals(__LINE__, d1, 1.3); /* 3.4 (cont.) */ ! 104: dequals(__LINE__, d2, 1.0); ! 105: ! 106: #if ANSI8712 ! 107: iequals(__LINE__, *pi1, 0); ! 108: iequals(__LINE__, *pi2, 0); ! 109: iequals(__LINE__, *pi3, 0); ! 110: iequals(__LINE__, i16, 1); ! 111: #endif ! 112: ! 113: checkthat(__LINE__, pf == c3_4); ! 114: ! 115: ! 116: /* check out constant expressions contexts : bitfields, enums, sizeof array, case. */ ! 117: b.b = 2; ! 118: iequals(__LINE__, b.b, 0); ! 119: #if (V7 || ANSI) ! 120: iequals(__LINE__, e2, 2); ! 121: iequals(__LINE__, e1, 1); ! 122: #endif ! 123: iequals(__LINE__, sizeof(carray), 10); ! 124: ! 125: count = -1; ! 126: for (i = 0; i < 4; ++i) ! 127: switch (i) ! 128: { ! 129: case (6*2) - (3 * 4): ! 130: count = 0; ! 131: break; ! 132: case 15 % 14: ! 133: count += 1; ! 134: break; ! 135: case 1<<1: ! 136: count += 2; ! 137: break; ! 138: case 0?17:3: ! 139: count += 3; ! 140: break; ! 141: default : ! 142: count = -1; ! 143: break; ! 144: } ! 145: iequals(__LINE__, count, 6); ! 146: } ! 147: ! 148: #else /* if SKIP34 */ ! 149: ! 150: void c3_4() { pr_skip("c3_4: SKIPPED ENTIRELY\n"); } ! 151: #endif /* SKIP34 */ ! 152:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.