Annotation of researchv10no/cmd/lcc/ph/c31.c, revision 1.1.1.1

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 SKIP31
                     12: /*
                     13:  * 3.1 - Lexical Elements
                     14:  */
                     15: #include "defs.h"
                     16: #if ANSI
                     17: #include <stddef.h>
                     18: #endif
                     19: /*
                     20:  * 3.1.1 - Keywords. These are tested throughout.
                     21:  */
                     22: static void c3_1_1(){}
                     23: 
                     24: /*
                     25:  * 3.1.2 - Identifiers.  A few checks for valid identifiers.
                     26:  */
                     27: static void c3_1_2()
                     28:         {
                     29:         int abcdefghijklmnopqrstuvwxyz = 1;
                     30:         int ABCDEFGHIJKLMNOPQRSTUVWXYZ = 2;
                     31:         int a23456789012345678901234567890a = 3;
                     32: #if ANSI
                     33:         int a23456789012345678901234567890b = 4;
                     34: 
                     35:        /* ANSI requires 31 characters of significance */
                     36:        inotequals(__LINE__,
                     37:                a23456789012345678901234567890b,
                     38:                a23456789012345678901234567890a);
                     39: #endif
                     40: 
                     41:        /* upper and lower cases are significant */
                     42:        inotequals(__LINE__,
                     43:                abcdefghijklmnopqrstuvwxyz,
                     44:                ABCDEFGHIJKLMNOPQRSTUVWXYZ);
                     45: 
                     46: #if !(LONG_IDENTIFIERS || ANSI)
                     47:        /* K&R/V7 declares that significance is ONLY to 8 characters */
                     48:        iequals(__LINE__, a23456789, a2345678);
                     49: #endif
                     50:        }
                     51: 
                     52: 
                     53: /*
                     54:  * 3.1.2.1 - Scopes of Identifiers
                     55:  */
                     56: #if ANSI && HAS_PROTOTYPES
                     57: /* function prototype scope */
                     58: int nofunc(int i);
                     59: #endif
                     60: 
                     61: /* file scope */
                     62: static int i = 17;
                     63: enum {AA, BB};
                     64: #if ANSI
                     65: static int f(enum {BB, AA} n) { iequals(__LINE__, BB, 0); return BB; }
                     66: #endif /* ANSI */
                     67: struct tag1 { int stuff; };    /* at file level */
                     68: static void c3_1_2_1(i)
                     69:        int i; /*  block scope (set to 19 from call above) */
                     70:        {
                     71:                {
                     72:                /* block scope */
                     73:                int i = ivalue(18);
                     74:                iequals(__LINE__, i, 18);
                     75:                }
                     76:        iequals(__LINE__, i, 19);
                     77:        iequals(__LINE__, BB, 1);
                     78: #if ANSI8703
                     79:        {
                     80:        enum { A, B = A+7 } e = A;
                     81:        int i;
                     82:        static struct tag1 { struct tag1 *next; } s1 = {&s1};   /* new scope */
                     83:        iequals(__LINE__, f(0), 0);
                     84:        checkthat(__LINE__, s1.next == &s1);
                     85:                {
                     86: #if ANSI8809
                     87:                void nonexist(union tag2 *junk);        /* tag2, in prototype scope, disappears */
                     88: #endif
                     89:                i = sizeof(struct tag2 { int stuff; }); /* declares tag2 */
                     90:                        {
                     91:                        struct tag2 s = {1};
                     92:                        checkthat(__LINE__, s.stuff == 1);
                     93:                        }
                     94:                } 
                     95:        } 
                     96: #endif 
                     97: #if ANSI 
                     98:        goto a; 
                     99:        { iequals(__LINE__, 1, 0); /* should not be reached */ a: ; } 
                    100: #endif 
                    101:        } 
                    102: 
                    103: /*
                    104:  * 3.1.2.2 - Linkages of identifiers
                    105:  */
                    106: static int s11 = 11;           /* "lex 1st decl w file scope" says "static" --> internal */
                    107:                int g13 = 13;           /* no "static" -->  external */
                    108:         int g13;                       /* no sc --> external */
                    109: extern int s11;                                /* same linkage as previous --> internal */
                    110: extern int g13;                                /* same linkage as previous --> external */
                    111: static int s16();                      /* internal linkage */
                    112:        int s16();                      /* no sc (on fn) --> as though "extern" (same as previous) */
                    113: 
                    114: static void c3_1_2_2()
                    115:        {
                    116:        int j9 = ivalue(9);             /* no linkage */
                    117:        extern int s11;                 /* internal linkage (already defined) */
                    118:        static int e12 = 12;    /* no linkage */
                    119:        extern int g13;                 /* external linkage (already defined) */
                    120:        extern int g14;                 /* external linkage (forward reference) */
                    121:        extern int e15;                 /* external linkage (defined in main1.c) */
                    122: 
                    123:        /* this is not referenced and shouldn't require any linkage */
                    124:        extern int notdefinedanywhere;
                    125:        iequals(__LINE__, j9, 9);
                    126:        iequals(__LINE__, s11, 11);
                    127:        iequals(__LINE__, g13, 13);
                    128:        iequals(__LINE__, g14, 14);
                    129:        iequals(__LINE__, e15, 15);
                    130:        iequals(__LINE__, s16(), 16);
                    131: 
                    132:        /* this should have internal linkage -- it is erroneous to link
                    133:         * to the static variable below.
                    134:         */
                    135:        iequals(__LINE__, e12, 12);
                    136: 
                    137:        /* scope testing of 'static i' from c3_1_2_1 */
                    138:        iequals(__LINE__, i, 17);
                    139: 
                    140:        /* test scoping into and out of include files */
                    141:                {
                    142:                int i = 9;
                    143: #include "c31sco.h"
                    144:                iequals(__LINE__, i, 10);
                    145:                }
                    146:        iequals(__LINE__, i, 17);
                    147:        }
                    148: 
                    149: static int e12 = 0;
                    150:                int g14 = 14;
                    151: 
                    152: static int s16() { return ivalue(16); }
                    153: /*
                    154:  * 3.1.2.3 - Name spaces of identifiers.
                    155:  * K&R and V7 have 2 (variables/labels and tags/members);
                    156:  * later UNIX (set TAG_AND_MEMB_SPACES to 1) has 3 (var/labels, tags, members);
                    157:  * ANSI has 4 (variables, labels, tags, members).
                    158:  */
                    159: static void c3_1_2_3()
                    160:        {
                    161:        int ident;
                    162: 
                    163: #if (TAG_AND_MEMB_SPACES || ANSI)
                    164:        struct ident
                    165:                {
                    166:                int xxx;
                    167:                int ident; /* members and variables in different spaces */
                    168:                }p;
                    169: #endif
                    170:        struct a
                    171:                {
                    172:                int ident2;
                    173:                } pa;
                    174: #if (ANSI || UNIQ_MEMB_NAMES)
                    175:        struct b
                    176:                {
                    177:                long ident2;
                    178:                } pb;
                    179: #endif
                    180: 
                    181:        ident = ivalue(7);
                    182:        pa.ident2 = ivalue(8);
                    183: #if ANSI
                    184:        {
                    185:        struct x { int x; } x = { 6 };
                    186:        iequals(__LINE__, x.x, ivalue(6));
                    187:        }
                    188:        if (ident)
                    189:                goto ident;
                    190: #else
                    191:        if (ident)
                    192:                goto ident1;
                    193: #endif
                    194: 
                    195:        /* this statement should never be reached */
                    196:        complain(__LINE__);
                    197: 
                    198: 
                    199: 
                    200: 
                    201: 
                    202: 
                    203:                                                                                                                                                                                /* 3.1.2.3 (cont.) */
                    204: #if ANSI
                    205:        ident:
                    206: #else
                    207:        ident1:
                    208: #endif
                    209:        iequals(__LINE__, pa.ident2, 8);
                    210: 
                    211: #if (TAG_AND_MEMB_SPACES || ANSI)
                    212:        p.ident = ivalue(9);
                    213:        iequals(__LINE__, p.ident, 9);
                    214: #endif
                    215:        }
                    216: 
                    217: 
                    218: 
                    219: 
                    220: 
                    221: 
                    222: 
                    223: 
                    224: 
                    225: 
                    226: 
                    227: 
                    228: 
                    229: 
                    230: 
                    231: 
                    232: 
                    233: 
                    234: 
                    235: 
                    236: 
                    237: 
                    238: 
                    239: 
                    240: 
                    241: 
                    242: 
                    243: 
                    244: 
                    245: 
                    246: 
                    247: 
                    248: 
                    249: 
                    250: 
                    251: 
                    252: 
                    253: /*
                    254:  * 3.1.2.4 - Storage classes of objects.
                    255:  */
                    256: static void c3_1_2_4(arg)
                    257:        int arg;
                    258:        {
                    259:        static int i = 0;
                    260:        int j = 17;
                    261: 
                    262:        /* make sure static items are still alive at each invocation */
                    263:        if (arg == 0)
                    264:                {
                    265:                i = 13;
                    266:                /* recursion ensures that stack frames (if any) don't coincide */
                    267:                c3_1_2_4(1);
                    268:                }
                    269:        else
                    270:                {
                    271:                iequals(__LINE__, i, 13);
                    272:                goto label;
                    273:                }
                    274: 
                    275:        for (i = 1; i <= 2; ++i)
                    276:                {
                    277:                int j = i + 1;
                    278: 
                    279:                iequals(__LINE__, j, i + 1);    /* auto var of inner block */
                    280:                }
                    281:                {
                    282:                int j = 14;
                    283: label:
                    284:                j = 15;
                    285:                }
                    286:        
                    287:        iequals(__LINE__, j, 17);
                    288: 
                    289:        /* local items might hold their values, but it is only coincidence */
                    290:        }
                    291: 
                    292: 
                    293: 
                    294: 
                    295: 
                    296: 
                    297: 
                    298: 
                    299: 
                    300: 
                    301: 
                    302: 
                    303: /*
                    304:  * 3.1.2.5 - Types
                    305:  */
                    306: char a_incomplete[]; char a_incomplete[3] = "ab";
                    307: static void c3_1_2_5()
                    308:        {
                    309:        static char Carray[] = 
                    310:                {
                    311:                'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
                    312:                'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 
                    313:                'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 
                    314:                'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 
                    315:                ',', '.', '/', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 
                    316:                '-', '=', '|', '<', '>', '?', '!',      '#',      '%', '^', '&',
                    317:                     '"', '~', '[', ']', '{', '}', '*', '(', ')', '_', '+', '\\',
                    318:                '\'', 
                    319:                };      /* dollar-sign, accent-grave, and at-sign are not in C source set */
                    320: 
                    321: #if ANSI
                    322:        signed char sc;
                    323:        signed short ss;
                    324:        signed int si;
                    325:        signed long sl;
                    326:        long double ld;
                    327:        struct s_incomplete *psinc;
                    328:        struct s_incomplete { int i; } sinc = {3};
                    329: #endif
                    330:        char c;
                    331:        short int s;
                    332:        int i;
                    333:        long int li;
                    334:        float f;
                    335:        double d;
                    336:        unsigned int ui;
                    337: 
                    338: 
                    339:        UCHAR uc;
                    340:        USHORT us;
                    341:        ULONG int ul;
                    342: 
                    343:        checkthat(__LINE__, sizeof(a_incomplete) == 3);
                    344:        checkthat(__LINE__, sizeof(c) <= sizeof(s));
                    345:        checkthat(__LINE__, sizeof(s) <= sizeof(i));
                    346:        checkthat(__LINE__, sizeof(i) <= sizeof(li));
                    347:        checkthat(__LINE__, sizeof(f) <= sizeof(d));
                    348:        checkthat(__LINE__, sizeof(uc) == sizeof(c));
                    349:        checkthat(__LINE__, sizeof(us) == sizeof(s));
                    350:        checkthat(__LINE__, sizeof(ui) == sizeof(i));
                    351:        checkthat(__LINE__, sizeof(ul) == sizeof(li));
                    352: 
                    353: #if ANSI                                                                                                                                                               /* 3.1.2.5 (cont.) */
                    354:        psinc = &sinc;
                    355:        iequals(__LINE__, psinc->i, 3);
                    356:        checkthat(__LINE__, sizeof(d) <= sizeof(ld));
                    357:        checkthat(__LINE__, sizeof(uc) == sizeof(sc));
                    358:        checkthat(__LINE__, sizeof(us) == sizeof(ss));
                    359:        checkthat(__LINE__, sizeof(ui) == sizeof(si));
                    360:        checkthat(__LINE__, sizeof(ul) == sizeof(sl));
                    361: #endif
                    362:        
                    363:        /* all source char constants are positive */
                    364:        for (i = 0; i < sizeof(Carray); ++i)
                    365:                checkthat(__LINE__, Carray[i] > 0);
                    366: #if ANSI
                    367:        /* <limits.h> is included in the "defs.h" for ANSI */
                    368:        checkthat(__LINE__, (int)INT_MAX == (unsigned int)INT_MAX);
                    369:        checkthat(__LINE__, (long)LONG_MAX == (unsigned long)LONG_MAX);
                    370: 
                    371:        checkthat(__LINE__, ULONG_MAX >= LONG_MAX);
                    372:        checkthat(__LINE__, UINT_MAX >= INT_MAX);
                    373:        checkthat(__LINE__, USHRT_MAX >= SHRT_MAX);
                    374:        ul = ULONG_MAX;
                    375:                {
                    376:                struct ints { char c; short s; int i; long l; };
                    377:                struct uints { UCHAR c; USHORT s; unsigned int i; ULONG l; };
                    378:                union { short s; unsigned short us; } u1;
                    379:                static char str2[] = "abc", str3[] = "abc";
                    380:                union { void *v2; char *s2; } u2;
                    381:                union { void *v3; char *s3; } u3;
                    382: 
                    383:                checkthat(__LINE__, sizeof(struct ints) == sizeof(struct uints));       /* ANSI8703 same alignments */
                    384:        
                    385:                /* ANSI8809 - "same representation and alignment" means interchangeable in args, returned values, and unions */
                    386:                u1.s = 10;
                    387:                iequals(__LINE__, abs(u1.us), ivalue(10));      /* no prototype for abs at this point, defaults */
                    388:                u2.s2 = str2, u3.s3 = str3;
                    389:                iequals(__LINE__, str_cmp(u2.v2, u3.v3), 0);    /* no prototype for str_cmp at this point, defaults */
                    390: 
                    391:                }
                    392:        checkthat(__LINE__, ul + ULONG_MAX > 0);        /* unsigned "can't oflo" */
                    393:        ui = UINT_MAX;
                    394:        checkthat(__LINE__, ui + UINT_MAX > 0);         /* unsigned "can't oflo" */
                    395:        us = USHRT_MAX;
                    396:        checkthat(__LINE__, us + USHRT_MAX > 0);        /* unsigned "can't oflo" */
                    397:        ldequals(__LINE__, (ul += 1), 0);       /* unsigned "can't oflo" */
                    398:        ldequals(__LINE__, (ui += 1), 0);       /* unsigned "can't oflo" */
                    399:        ldequals(__LINE__, (us += 1u), 0);      /* unsigned "can't oflo" */
                    400: #endif /* ANSI */
                    401:        }
                    402: 
                    403: #if ANSI8709
                    404: /*
                    405:  * 3.1.2.6 - Compatible type and composite type
                    406:  */
                    407: typedef char CHAR_COMPATIBLE;
                    408: extern struct s3126 { CHAR_COMPATIBLE i; signed int j; } s3126;        /* link with lang.c */
                    409: extern union u3126 { signed int j; CHAR_COMPATIBLE i; } u3126; /* link with lang.c */
                    410: extern enum e3126 { E3126B=5, E3126A=4 } e3126;                                        /* link with lang.c */
                    411: typedef void VF();                     /* no parm list */
                    412: typedef void VF_VF(VF *);      /* one parm of type VF * */
                    413: static void c3_1_2_6();
                    414: static void c3_1_2_6(VF *);
                    415: static void c3_1_2_6(VF_VF *);
                    416: static void c3_1_2_6(
                    417:        VF_VF *pf)
                    418:        {
                    419:        iequals(__LINE__, s3126.j, 2);
                    420:        iequals(__LINE__, u3126.i, 3);
                    421:        iequals(__LINE__, e3126, 5);
                    422:        checkthat(__LINE__, pf == c3_1_2_6);
                    423:        }
                    424: #endif
                    425: 
                    426: 
                    427: 
                    428: 
                    429: 
                    430: 
                    431: 
                    432: 
                    433: 
                    434: 
                    435: 
                    436: 
                    437: 
                    438: 
                    439: 
                    440: 
                    441: 
                    442: 
                    443: 
                    444: 
                    445: 
                    446: 
                    447: 
                    448: 
                    449: 
                    450: 
                    451: 
                    452: 
                    453: /*
                    454:  * 3.1.3.1 - Floating constants
                    455:  */
                    456: static void c3_1_3_1()
                    457:        {
                    458: 
                    459:        /* check multiple representations for equality */
                    460:        dequals(__LINE__, 123., 123.0); 
                    461:        dequals(__LINE__, 123.0, 12.3e1); 
                    462:        dequals(__LINE__, 12.3e1, 12.3E1); 
                    463:        dequals(__LINE__, 12.3E1, 1.23E+2); 
                    464:        dequals(__LINE__, 123.e-2, 12.3e-1);
                    465:        dequals(__LINE__, .9, 9e-1);
                    466:        checkthat(__LINE__, sizeof(double) == sizeof(1.0));
                    467: 
                    468: #if ANSI
                    469:        /* check for existance of long double constants */
                    470:        ldequals(__LINE__, 101.L, 101.0l); 
                    471:        fequals(__LINE__, 202.f, 202.0F);
                    472:        checkthat(__LINE__, sizeof(1.F) == sizeof(float) && sizeof(1.f) == sizeof(float));
                    473:        checkthat(__LINE__, sizeof(1.L) == sizeof(long double) && sizeof(1.l) == sizeof(long double));
                    474: #endif
                    475:        }
                    476: 
                    477: 
                    478: 
                    479: 
                    480: 
                    481: 
                    482: 
                    483: 
                    484: 
                    485: 
                    486: 
                    487: 
                    488: 
                    489: 
                    490: 
                    491: 
                    492: 
                    493: 
                    494: 
                    495: 
                    496: 
                    497: 
                    498: 
                    499: 
                    500: 
                    501: 
                    502: 
                    503: /*
                    504:  * 3.1.3.2 - Integer constants.
                    505:  */
                    506: static void c3_1_3_2()
                    507:        {
                    508:        /* make sure all hex digits are accepted */
                    509:        iequals(__LINE__, 0xabc, 0xABC);
                    510:        iequals(__LINE__, 0xdef, 0xDEF);
                    511: 
                    512:        /* equivalence checking */
                    513:        iequals(__LINE__, 456, 0x1c8);
                    514:        iequals(__LINE__, 456, 0710);
                    515: 
                    516:        /* size checking */
                    517:        iequals(__LINE__, sizeof(1), sizeof(int));
                    518:        iequals(__LINE__, sizeof(0xabc), sizeof(int));
                    519:        iequals(__LINE__, sizeof(0123), sizeof(int));
                    520:        iequals(__LINE__, sizeof(1L), sizeof(long));
                    521:        iequals(__LINE__, sizeof(0xabcL), sizeof(long));
                    522:        iequals(__LINE__, sizeof(0123L), sizeof(long));
                    523:        iequals(__LINE__, sizeof(1l), sizeof(long));
                    524:        iequals(__LINE__, sizeof(0xabcl), sizeof(long));
                    525:        iequals(__LINE__, sizeof(0123l), sizeof(long));
                    526:        iequals( - __LINE__, sizeof(999999999), sizeof(long));
                    527:        iequals( - __LINE__, sizeof(0x9999999), sizeof(long));
                    528:        iequals( - __LINE__, sizeof(0777777777), sizeof(long));
                    529:        /* the 3 lines above are not strict - could fit a very large int */
                    530: #if ANSI
                    531:        /* check for existence of both U and L suffixes */
                    532:        iequals(__LINE__, sizeof(1u), sizeof(unsigned int));
                    533:        iequals(__LINE__, sizeof(1U), sizeof(unsigned int));
                    534:        iequals(__LINE__, sizeof(1LU), sizeof(unsigned long));
                    535:        iequals(__LINE__, sizeof(1lU), sizeof(unsigned long));
                    536:        iequals(__LINE__, sizeof(01uL), sizeof(unsigned long));
                    537:        iequals(__LINE__, sizeof(0x1ul), sizeof(unsigned long));
                    538: #endif
                    539: 
                    540: /* ANSI requires that 0xffff be unsigned int (if too big for int),
                    541:  * but that 65535 be long (if too big for int).
                    542:  */
                    543: #if ANSI
                    544:        iequals(__LINE__, sizeof(0xffff), sizeof(unsigned int));
                    545:        if (MAX_UINT == 65535)
                    546:                {
                    547:                iequals(__LINE__, sizeof(65535), sizeof(long));
                    548:                iequals(__LINE__, sizeof(65535u), sizeof(unsigned int));
                    549:                iequals(__LINE__, sizeof(0xffff), sizeof(int));
                    550:                }
                    551:        else
                    552:                {
                    553:                checkthat(__LINE__, sizeof(65535) <= sizeof(long));
                    554:                iequals(__LINE__, sizeof(65535u), sizeof(unsigned int));
                    555:                iequals(__LINE__, sizeof(0xffff), sizeof(int));
                    556:                }
                    557: #endif
                    558:        }
                    559: /*
                    560:  * 3.1.3.3 - Enumeration constants.
                    561:  */
                    562: static void c3_1_3_3()
                    563:        {
                    564: #if (V7 || ANSI)
                    565:        enum color { red = -1, blue = -2, green = (MAX_INT-1-MAX_INT) /* i.e., -1 again */ };
                    566:        checkthat(__LINE__, sizeof(red) <= sizeof(int));
                    567:        iequals(__LINE__, red, ivalue(-1));
                    568:        iequals(__LINE__, blue, ivalue(-2));
                    569:        iequals(__LINE__, green, ivalue(-1));
                    570: #endif
                    571:        }
                    572: 
                    573: 
                    574: 
                    575: 
                    576: 
                    577: 
                    578: 
                    579: 
                    580: 
                    581: 
                    582: 
                    583: 
                    584: 
                    585: 
                    586: 
                    587: 
                    588: 
                    589: 
                    590: 
                    591: 
                    592: 
                    593: 
                    594: 
                    595: 
                    596: 
                    597: 
                    598: 
                    599: 
                    600: 
                    601: 
                    602: 
                    603: 
                    604: 
                    605: 
                    606: 
                    607: 
                    608: 
                    609: /*
                    610:  * 3.1.3.4 - Character constants.
                    611:  */
                    612: static void c3_1_3_4()
                    613:        {
                    614:        int c;
                    615: 
                    616:        /* the basic set of character constants was tested above */
                    617: 
                    618:        /* escape sequence character constants */
                    619:        inotequals(__LINE__, '\b', 'b');
                    620:        inotequals(__LINE__, '\f', 'f');
                    621:        inotequals(__LINE__, '\n', 'n');
                    622:        inotequals(__LINE__, '\r', 'r');
                    623:        inotequals(__LINE__, '\t', 't');
                    624:        iequals(__LINE__, '\"', '"');
                    625:        iequals(__LINE__, '\\', "\\"[0]);
                    626: 
                    627: #if ANSI
                    628:        inotequals(__LINE__, '\a', 'a');
                    629:        inotequals(__LINE__, '\v', 'v');
                    630: 
                    631:        /* hex digit form */
                    632:        iequals(__LINE__, '\xa', 0xa);
                    633:        iequals(__LINE__, '\x7b', 0x7b);
                    634:        iequals(__LINE__, '\x001', 1);
                    635: #if WIDE_CHARS
                    636: #include "c3134.h"  /* to hide the following lines from non-ANSI lexical scan */
                    637: /*     checkthat(__LINE__, sizeof(L'x') == sizeof(wchar_t)); */
                    638: /*     iequals(__LINE__, L'a', 'a'); */
                    639: /*     iequals(__LINE__, L'\0', 0); */
                    640: #endif
                    641: 
                    642: #endif
                    643: 
                    644:        /* octal digit form */
                    645:        iequals(__LINE__, '\0', 0);
                    646:        iequals(__LINE__, '\1', 1);
                    647:        iequals(__LINE__, '\12', 012);
                    648:        iequals(__LINE__, '\123', 0123);
                    649:        
                    650:        iequals(__LINE__, sizeof('0'), sizeof(int));
                    651: 
                    652: 
                    653: 
                    654: 
                    655: 
                    656: 
                    657: 
                    658: 
                    659: #if (SIGNED_CHAR == 1 && MAX_UCHAR == 0xff)                                                                                            /* 3.1.3.4 (cont.) */
                    660:        /* character constants sign extend */
                    661:        iequals(__LINE__, '\377', -1);
                    662: #else
                    663: #if UNSIGNED_CHAR
                    664:        /* character constants do not sign extend */
                    665:        iequals(__LINE__, '\377', 255);
                    666: #endif
                    667: #endif
                    668:        }
                    669: 
                    670: /*
                    671:  * 3.1.4 - String literals.
                    672:  */
                    673: int distinct(s)
                    674:        char *s;
                    675:        {
                    676:        int i, j;
                    677: 
                    678:        for (i = 0; s[i] != '\0'; ++i)
                    679:                {
                    680:                for (j = 0; s[j] != s[i]; ++j)
                    681:                        ;
                    682:                if (i != j)
                    683:                        return (0);             /* s[i] is dup'ed by an earlier char */
                    684:                }
                    685:        return (1);
                    686:        }
                    687: #define OLD_ESC_CHARS "\"\\\b\f\n\r\t"
                    688: #define SOURCE_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\
                    689: 0123456789!#%&'()*+,-./:;<=>?[]^_{|}~"
                    690: static void c3_1_4()
                    691:        {
                    692:        static char *p = "abc";
                    693:        static char *q = OLD_ESC_CHARS;
                    694:        static char *r = "abc";
                    695:        /* check out all legal characters */
                    696:        static char *s = SOURCE_CHARS;
                    697:        static char *z = "";
                    698: 
                    699:        /* empty string */
                    700:        iequals(__LINE__, z[0], 0);
                    701:        
                    702:        /* check for "array of char" behaviour and trailing null */
                    703:        iequals(__LINE__, p[0], 'a');
                    704:        iequals(__LINE__, p[1], 'b');
                    705:        iequals(__LINE__, p[2], 'c');
                    706:        iequals(__LINE__, p[3], '\0');
                    707: 
                    708: 
                    709:                                                                                                                                                                                /* 3.1.3.4 (cont.) */
                    710:        /* check escape sequences */
                    711:        checkthat(__LINE__, distinct(q));
                    712:        checkthat(__LINE__, distinct(s));
                    713:        iequals(__LINE__, q[0], '\"');
                    714:        iequals(__LINE__, q[1], '\\');
                    715:        iequals(__LINE__, q[2], '\b');
                    716:        iequals(__LINE__, q[3], '\f');
                    717:        iequals(__LINE__, q[4], '\n');
                    718:        iequals(__LINE__, q[5], '\r');
                    719:        iequals(__LINE__, q[6], '\t');
                    720: 
                    721: #if ANSI
                    722: #define NEW_ESC_CHARS "\a\v"
                    723:                {
                    724:                /* extra escape characters and string catenation */
                    725:                static char *s = NEW_ESC_CHARS;
                    726:                static char *t = "abc""def";
                    727:                static char *u = SOURCE_CHARS OLD_ESC_CHARS NEW_ESC_CHARS ;
                    728:                iequals(__LINE__, s[0], '\a');
                    729:                iequals(__LINE__, s[1], '\v');
                    730:                iequals(__LINE__, t[3], 'd');
                    731:                iequals(__LINE__, t[6], '\0');
                    732:                checkthat(__LINE__, distinct(u));
                    733:                }
                    734: #endif
                    735: 
                    736: #if V7 /* this changed in ANSI */
                    737:        /* check for distinctness and writability of strings */
                    738:                {
                    739:                static char *u = "xyz";
                    740:                static char *t = "xyz";
                    741:        
                    742:                u[0] = ivalue(0);
                    743:                iequals(__LINE__, u[0], 0);
                    744:                inotequals(__LINE__, t[0], 0);
                    745:                }
                    746: #endif
                    747:        /* pure numbers through escapes */
                    748:        s = "\0123";
                    749:        iequals(__LINE__, 012, s[0]);
                    750:        iequals(__LINE__, '3', s[1]);
                    751: #if ANSI
                    752:        s = "\x012""3";                                         /* The catenation "" is needed for ANSI8706 */
                    753:        iequals(__LINE__, 0x12, s[0]);                                                  /* See 3.1.4 Example */
                    754:        iequals(__LINE__, '3', s[1]);
                    755: #if ANSI8706
                    756:        checkthat(__LINE__, str_cmp("\x023", "\x02""3") != 0);  /* ANSI8706 */
                    757: #endif
                    758: #endif
                    759:                                                                                                                                                                                /* 3.1.4 (cont.) */
                    760:        /* strings are arrays of chars */
                    761:        iequals(__LINE__, "abcd"[0], 'a');
                    762:        iequals(__LINE__, "abcd"[1], 'b');
                    763:        iequals(__LINE__, "abcd"[2], 'c');
                    764:        iequals(__LINE__, "abcd"[3], 'd');
                    765:        iequals(__LINE__, "abcd"[4], 0);
                    766:        }
                    767: 
                    768: /*
                    769:  * Operators.
                    770:  * No capability requirements.
                    771:  * Each operator will be tested later (c3_3 etc.).
                    772:  */
                    773: static void c3_1_5(){}
                    774: 
                    775: /*
                    776:  * Punctuators.
                    777:  * No capability requirements.
                    778:  * Each use of punctuator in syntax will be tested later (c3_5, c3_6, c3_7, c3_8).
                    779:  */
                    780: static void c3_1_6(){}
                    781: 
                    782: /* 3.1.7 - Header names (tested throughout) */
                    783: 
                    784: /*
                    785:  * 3.1.8 - Preprocessing numbers
                    786:  */
                    787: #if ANSI
                    788:        #define STR(a) NXSTR(a)
                    789:        #define NXSTR(a) #a
                    790: #endif
                    791: static void c3_1_8()
                    792:        {
                    793: #if PP_CAT_AND_STR
                    794: #include "c318.h" /* to prevent non-ANSI lexical scan of ... */
                    795: /*     #define CAT(a, b) NXCAT(a, b) */
                    796: /*     #define NXCAT(a, b) a ## b */
                    797: /*     iequals(__LINE__, str_cmp(STR(CAT(1., E9)), "1.E9"), 0); */
                    798: /*     iequals(__LINE__, str_cmp(STR(CAT(1.u, 1E+)), "1.u1E+"), 0); */
                    799: /* #define E 2 */
                    800: /*     checkthat(__LINE__, 1E1 == 10.); */
                    801: #endif
                    802:        }
                    803: 
                    804: 
                    805: 
                    806: 
                    807: 
                    808: 
                    809: /*
                    810:  * Comments - 3.1.9
                    811:  */
                    812: /* /* no nesting */
                    813: /* comment prevents preprocessing of its contents...
                    814: #include "unknown"
                    815: */
                    816: 
                    817: static void c3_1_9()
                    818:        {
                    819:        int i;
                    820:        char c;
                    821:        char *s;
                    822: 
                    823: 
                    824: 
                    825: 
                    826: 
                    827:        i = 2; s = "/*"; i = 3; /* no comment in string literal */
                    828:        iequals(__LINE__, i, 3);
                    829:        /* comment prevents compilation of its contents...
                    830:        complain(__LINE__);
                    831:        */
                    832:        }
                    833: 
                    834: 
                    835: 
                    836: 
                    837: 
                    838: 
                    839: 
                    840: 
                    841: 
                    842: 
                    843: 
                    844: 
                    845: 
                    846: 
                    847: 
                    848: 
                    849: 
                    850: 
                    851: 
                    852: 
                    853: 
                    854: 
                    855: 
                    856: 
                    857: 
                    858: 
                    859: /*
                    860:  * 3.1 - Lexical elements
                    861:  */
                    862: void c3_1()
                    863:        {
                    864:        int a = 1;
                    865:        int b = 2;
                    866:        int c = 3;
                    867: 
                    868:        Filename = "c31.c";
                    869: 
                    870:        /* check for insignificance of white space */
                    871: #if ANSI
                    872: #include "c31h.h"
                    873:        Filename = "c31.c";
                    874: #else
                    875:        iequals(__LINE__, (a+b-c),  (a +        b
                    876:                                                        /* */-
                    877:                                                        c));
                    878: #endif
                    879: 
                    880:        /* a token uses the longest sequence of characters */
                    881:        iequals(__LINE__, c+++b, 5);
                    882:        iequals(__LINE__, b, 2);
                    883:        iequals(__LINE__, c, 4);
                    884: 
                    885:        c3_1_1();
                    886:        c3_1_2();
                    887:        c3_1_2_1(19);
                    888:        c3_1_2_2();
                    889:        c3_1_2_3();
                    890:        c3_1_2_4(0);
                    891:        c3_1_2_5();
                    892: #if ANSI8709
                    893:        c3_1_2_6(&c3_1_2_6);
                    894: #endif
                    895:        c3_1_3_1();
                    896:        c3_1_3_2();
                    897:        c3_1_3_3();
                    898:        c3_1_3_4();
                    899:        c3_1_4();
                    900:        c3_1_5();
                    901:        c3_1_6();
                    902:        c3_1_8();
                    903:        c3_1_9();
                    904:        }
                    905: #else /* if SKIP31 */
                    906: 
                    907: void c3_1() { pr_skip("c3_1: SKIPPED ENTIRELY\n"); }
                    908: #endif /* SKIP31 */
                    909: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.