|
|
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 SKIP38 ! 12: /* ! 13: * 3.8 - Preprocessor directives ! 14: */ ! 15: #include "defs.h" ! 16: ! 17: static char save_date[20], save_time[20]; ! 18: static char tmp_str[20]; ! 19: static int f(n) int n; { return (n); } ! 20: ! 21: void c3_8_1(); ! 22: void c3_8_2(); ! 23: void c3_8_3(); ! 24: void c3_8_4(); ! 25: void c3_8_5(); ! 26: void c3_8_6(); ! 27: void c3_8_7(); ! 28: void c3_8_8(); ! 29: ! 30: void c3_8() ! 31: { ! 32: Filename = "c38.c"; ! 33: ! 34: #if ANSI8709 ! 35: str_cpye(save_date, __DATE__); /* to be tested in c3_8_8 */ ! 36: str_cpye(save_time, __TIME__); ! 37: #endif ! 38: c3_8_1(); ! 39: c3_8_2(); ! 40: c3_8_3(); ! 41: c3_8_4(); ! 42: c3_8_5(); ! 43: c3_8_6(); ! 44: c3_8_7(); ! 45: c3_8_8(); ! 46: } ! 47: ! 48: ! 49: ! 50: /* ! 51: * 3.8.1 - conditional inclusion ! 52: */ ! 53: void c3_8_1() ! 54: { ! 55: #define X 0 ! 56: #define Y 1 ! 57: int i, j, k; ! 58: ! 59: i = j = k = 0; ! 60: ! 61: #if 0 ! 62: complain(__LINE__); ! 63: #endif ! 64: ! 65: #if ANSI ! 66: #include "c381.h" ! 67: /* contents of included file: ! 68: * Filename = "c381.h"; ! 69: * #if !defined X ! 70: * syntax error !!! ! 71: * #elif !defined (X) ! 72: * syntax error !!! ! 73: * #endif ! 74: * #define c3835 1 ! 75: */ ! 76: Filename = "c38.c"; ! 77: #if c3835 != 1 ! 78: complain(__LINE__); ! 79: #endif ! 80: #endif ! 81: #if !~~0 == (1*2/3%4+6-5^7&8|9) || 10 > 11 && 12 >= 13 ! 82: complain(__LINE__); ! 83: #endif ! 84: #if UNDEFINED_NAME ! 85: complain(__LINE__); ! 86: #endif ! 87: #if X ! 88: complain(__LINE__); ! 89: #endif ! 90: #if ANSI ! 91: #if ~0 > 2147483647 ! 92: complain(__LINE__); ! 93: #endif ! 94: ! 95: #if '\33' != 033 /* interpretation of escapes is implem-defined */ ! 96: complain(- __LINE__); ! 97: #endif ! 98: ! 99: #if Y ! 100: i = 3; ! 101: #elif Y ! 102: i = 4; ! 103: #endif ! 104: iequals(__LINE__, i, 3); ! 105: #endif ! 106: ! 107: /* test nesting and else clauses */ ! 108: #ifdef /* comments can appear anywhere */X ! 109: #ifndef UNDEFINED_NAME /* comments can appear anywhere */ ! 110: i = 7; ! 111: #else ! 112: complain(__LINE__); ! 113: #endif ! 114: #else ! 115: complain(__LINE__); ! 116: #endif /* comments can appear anywhere */ ! 117: iequals(__LINE__, i, 7); ! 118: } ! 119: ! 120: /* ! 121: * 3.8.2 - Source file inclusion ! 122: */ ! 123: #if ANSI ! 124: #define NXSTR(a) #a /* See 3.8.3.2 */ ! 125: #include NXSTR(stdarg.h) /* produces "stdarg.h", then looks for <stdarg.h> */ ! 126: #endif /* ANSI */ ! 127: ! 128: void c3_8_2() ! 129: { ! 130: char *p = NULL; ! 131: #if ANSI ! 132: # define INCLUDE "c382a.h" ! 133: # include INCLUDE ! 134: #else ! 135: #include "c382a.h" ! 136: #endif /* ANSI */ ! 137: /* contents of "c382a.h": #include "c382b.h" ! 138: * contents of "c382b.h": int i; ! 139: */ ! 140: i = 1; /* syntax error if the include is wrong */ ! 141: #if ANSI && !defined(va_start) /* to prove inclusion of <stdarg.h> */ ! 142: complain(__LINE__); ! 143: #endif ! 144: } ! 145: ! 146: ! 147: /* ! 148: * 3.8.3 - Macro replacement ! 149: */ ! 150: void c3_8_3() ! 151: { ! 152: #define INT_I_J_K int i, j, k; /* object-like macro */ ! 153: #define NOTHING ! 154: #define INIT() = 1; /* fn-like macro, no args */ ! 155: ! 156: INT_I_J_K /* semi-colon is part of macro */ ! 157: ! 158: NOTHING /* syntax error if anything remains */ ! 159: i INIT() /* semi-colon is part of def -- i = 1; */ ! 160: j INIT() ! 161: k INIT() ! 162: ! 163: #if ANSI ! 164: #define OBJ 1 + 1 ! 165: #define OBJ 1 +/* comment is whitespace */1 ! 166: #define OBJ 1 + 1 ! 167: # define/* */OBJ 1 + 1 ! 168: iequals(__LINE__, OBJ, 2); ! 169: ! 170: #define FN(a) 1 + 1 ! 171: #define FN(a) 1 + /* comment is whitespace */ 1 ! 172: #define FN(a) 1 + 1 ! 173: # define /* */ FN(a) 1 + 1 ! 174: iequals(__LINE__, FN(0), 2); ! 175: ! 176: #define define 1 ! 177: # define A 2 ! 178: iequals(__LINE__, A, 2); ! 179: #undef define ! 180: #undef A ! 181: #endif ! 182: /* comments can be embedded in other preprocessor statements */ ! 183: #define /* */ SUM(c, /* */b, a) (a+b+/* */c /* */) ! 184: ! 185: /* grouping parenthesis and commas inside don't affect expansion ! 186: * Also, comments can now be ANYWHERE in the text. */ ! 187: #if ANSI ! 188: iequals(__LINE__, SUM(/* */(7,/* */i), ! 189: (((3,j))),k), 3); ! 190: #endif ! 191: /* make sure that macro expansion is literal, e.g., does no C grouping */ ! 192: #define ADD(a,b) a+b ! 193: iequals(__LINE__, ADD(2,3)*4, 14); ! 194: ! 195: ! 196: /* 3.8.3 (cont.) */ ! 197: /* character constants and string literals are not scanned */ ! 198: inotequals(__LINE__, 'X', '0'); ! 199: inotequals(__LINE__, "X"[0], '0'); ! 200: ! 201: /* nested definitions -- also, commas in expansion don't affect the expansion */ ! 202: #define A B ! 203: #define B (j=1,C) ! 204: #define C X ! 205: iequals(__LINE__, A, 0); ! 206: ! 207: #if ANSI ! 208: ! 209: /* 3.8.3.1 - Argument substitution */ ! 210: #define f(a) (2 * f(a) + 1) ! 211: iequals(__LINE__, f(f(1)), 7); ! 212: #undef f ! 213: ! 214: /* 3.8.3.2 - The # operator */ ! 215: #define STR(a) NXSTR(a) ! 216: #define NXSTR(a) #a ! 217: #define NAME /* whitespace */ abc ! 218: ! 219: stequals(__LINE__, STR("\a"), "\"\\a\""); ! 220: stequals(__LINE__, STR(\7), "\7"); ! 221: stequals(__LINE__, STR(NAME), "abc"); ! 222: stequals(__LINE__, NXSTR(NAME), "NAME"); ! 223: stequals(__LINE__, NXSTR(a b), "a b"); ! 224: stequals(__LINE__, NXSTR( a ), "a"); ! 225: stequals(__LINE__, STR(Y.1), "1.1"); ! 226: #define f h ! 227: #define h(a) a+f ! 228: str_cpye(tmp_str, STR( f(1)(2) )); ! 229: if (str_cmp(tmp_str, "1+f(2)") != 0 && str_cmp(tmp_str, "1+h(2)") != 0) ! 230: stequals(__LINE__, tmp_str, "NEITHER '1+f(2)' NOR '1+h(2)'"); ! 231: ! 232: #undef f ! 233: #undef h ! 234: ! 235: ! 236: ! 237: ! 238: ! 239: ! 240: ! 241: ! 242: ! 243: ! 244: ! 245: ! 246: /* 3.8.3.3 - The ## operator */ ! 247: #if MACRO_NOV_86 ! 248: #define CAT(a, b) NXCAT(a, b) ! 249: #define NXCAT(a, b) a ## b ! 250: #define Xx x ! 251: { ! 252: int xy = 1; ! 253: ! 254: iequals(__LINE__, NXCAT(x, y), 1); ! 255: iequals(__LINE__, CAT(Xx, y), 1); ! 256: } ! 257: ! 258: #define pp1 x ## y ! 259: #define pp3(a) x ## a ! 260: #define xy b ! 261: #define cat3() x ## x ## y ! 262: #define op1(a) a ! 263: #define op(n, a) op ## n (a) ! 264: { ! 265: int xxy = 1; ! 266: int b = 2; ! 267: int x = 3; ! 268: ! 269: iequals(__LINE__, pp3(xy), 1); /* -> xxy */ ! 270: iequals(__LINE__, pp1, 2); /* -> xy -> b */ ! 271: iequals(__LINE__, pp3(y+2), 4); /* -> xy + 2 -> b + 2 */ ! 272: iequals(__LINE__, pp3(xy + xy), 3); /* -> xxy + xy -> xxy + b */ ! 273: iequals(__LINE__, cat3(), 1); /* -> xxy */ ! 274: iequals(__LINE__, op(1, xxy), 1); /* -> op1(xxy) -> xxy */ ! 275: } ! 276: #endif /* MACRO_NOV_86 */ ! 277: ! 278: /* 3.8.3.4 - Re-scanning and further replacement */ ! 279: #define f(a) f(1 + a ! 280: #define apply(f, n) f(n) ! 281: { ! 282: #if MACRO_NOV_86 ! 283: iequals(__LINE__, f(1) ), 2); /* -> f(1 + 1 ) */ ! 284: iequals(__LINE__, f(f(2)) )), 4); /* -> f(1 + f(1 + 2 )) */ ! 285: iequals(__LINE__, f(1) + f(1) )), 4); /* -> f(1 + 1 + f(1 + 1 )) */ ! 286: iequals(__LINE__, apply(f, 2) ), 3); /* -> f(2) ) -> f(1 + 2 ) */ ! 287: #endif ! 288: #undef f ! 289: #define f g ! 290: #define g f ! 291: iequals(__LINE__, f(1), 1); /* -> g(1) -> f(1) */ ! 292: #define checkthat checkthat ( __LINE__, 0 == 0 ! 293: checkthat ); ! 294: #undef checkthat ! 295: } ! 296: /* 3.8.3.5 - Scope of macro definitions */ ! 297: #if !defined c3835 ! 298: complain(__LINE__); ! 299: #endif ! 300: #undef c3835 ! 301: #if defined c3835 ! 302: complain(__LINE__); ! 303: #endif ! 304: #undef c3835 ! 305: ! 306: #endif ! 307: ! 308: /* undef */ ! 309: #undef INIT ! 310: #define INIT = 2; ! 311: i INIT ! 312: j INIT ! 313: k INIT ! 314: iequals(__LINE__, SUM(i,j,k), 6); ! 315: ! 316: /* __LINE__ and __FILE__ have been checked throughout */ ! 317: ! 318: } /* end c3_8_3 */ ! 319: ! 320: /* ! 321: * 3.8.4 - line control ! 322: */ ! 323: void c3_8_4() ! 324: { ! 325: int i; ! 326: ! 327: #if (V7 || ANSI) ! 328: #line 32767 ! 329: i = __LINE__; ! 330: #line 336 "newfile" ! 331: iequals(__LINE__, i, 32767); ! 332: checkthat( - __LINE__, str_cmp(__FILE__, "newfile") == 0); ! 333: #line 339 "c38.c" ! 334: iequals(__LINE__, __LINE__, 339); ! 335: checkthat( - __LINE__, str_cmp(__FILE__, "c38.c") == 0); ! 336: #if ANSI ! 337: #define ALINE 10306 "X38.c" ! 338: ! 339: #line ALINE ! 340: i = __LINE__; ! 341: #line 347 ! 342: iequals(__LINE__, i, 10306); ! 343: checkthat( - __LINE__, str_cmp(__FILE__, "X38.c") == 0); ! 344: #line 350 "c38.c" ! 345: #endif /* ANSI */ ! 346: #endif /* V7 || ANSI */ ! 347: } /* end c3_8_4 */ ! 348: ! 349: /* ! 350: * 3.8.5 - #error directive ! 351: */ ! 352: void c3_8_5() ! 353: { ! 354: /* #error is tested in diagnostic-tests */ ! 355: } ! 356: ! 357: /* ! 358: * 3.8.6 - #pragma directive ! 359: */ ! 360: void c3_8_6() ! 361: { ! 362: #if ANSI ! 363: #include "c386.h" ! 364: /* contents of included file: ! 365: * #pragma ignore_this_unimplemented_pragma ! 366: */ ! 367: #endif ! 368: } ! 369: ! 370: /* ! 371: * 3.8.7 - Null directive ! 372: */ ! 373: void c3_8_7() ! 374: { ! 375: #if ANSI ! 376: # /* comments */ /* and other whitespace */ /* allowed */ ! 377: # ! 378: # ! 379: #endif ! 380: } ! 381: ! 382: ! 383: ! 384: ! 385: ! 386: ! 387: ! 388: ! 389: ! 390: ! 391: ! 392: ! 393: ! 394: ! 395: ! 396: ! 397: /* ! 398: * 3.8.8 - Predefined macro names ! 399: */ ! 400: void c3_8_8() ! 401: { ! 402: #if ANSI ! 403: /* __LINE__ and __FILE__ already tested */ ! 404: #if ANSI8709 ! 405: stequals(__LINE__, save_date, __DATE__); ! 406: stequals(__LINE__, save_time, __TIME__); ! 407: #endif /* ANSI8709 */ ! 408: iequals(__LINE__, str_len(__DATE__), 11); ! 409: iequals(__LINE__, __DATE__[3], ' '); ! 410: iequals(__LINE__, __DATE__[6], ' '); ! 411: iequals(__LINE__, __DATE__[7], '1'); ! 412: iequals(__LINE__, __DATE__[8], '9'); ! 413: iequals(__LINE__, str_len(__TIME__), 8); ! 414: iequals(__LINE__, __TIME__[2], ':'); ! 415: iequals(__LINE__, __TIME__[5], ':'); ! 416: iequals(__LINE__, __STDC__, 1); ! 417: #else ! 418: #ifdef __STDC__ ! 419: warning -- __STDC__ should only be pre-defined in conforming environment ! 420: #endif /* __STDC__ */ ! 421: #endif /* ANSI */ ! 422: } /* end c3_8 */ ! 423: ! 424: #else /* if SKIP38 */ ! 425: ! 426: void c3_8() { pr_skip("c3_8: SKIPPED ENTIRELY\n"); } ! 427: #endif /* SKIP38 */ ! 428:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.