Annotation of researchv10no/cmd/lcc/ph/c33c.c, revision 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 SKIP33C
        !            12: #include "defs.h"
        !            13: void strucs(), q_s_a(), unions();
        !            14: /*
        !            15:  * Structures ..... all sorts of tests of structures and unions
        !            16:  * Called at or about line 194 in c33a.c
        !            17:  */
        !            18: void structures()
        !            19:        {
        !            20:        Filename = "c33c.c";
        !            21: #if (ANSI || V7)
        !            22:        strucs();
        !            23:        q_s_a();
        !            24:        unions();
        !            25: #endif
        !            26:        }
        !            27: 
        !            28: #if (ANSI || V7)
        !            29: /*
        !            30:  * STRUCTS - this function tests the ways you can copy 
        !            31:  * structures. It tests 2 sizes of structures: S1 has a single 
        !            32:  * char element and SN has 20 int members plus a char. 
        !            33:  */
        !            34: typedef struct
        !            35:        {
        !            36:        char x;
        !            37:        } S1;
        !            38: typedef struct
        !            39:        {
        !            40:        int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t;
        !            41:        char z;
        !            42:        } SN;
        !            43: 
        !            44: extern S1 RetS1();
        !            45: extern SN RetSN();
        !            46: 
        !            47: void strucs()
        !            48:        {
        !            49:        REGISTERS;
        !            50:        S1 s1a, s1b, s1c;
        !            51:        SN sna, snb, snc;
        !            52:        int i, j;
        !            53:        static S1 s1array[12] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
        !            54: 
        !            55: 
        !            56:        USEREGISTERS;
        !            57: 
        !            58:        /* simple assignment */
        !            59:        s1a.x = ivalue(99);
        !            60:        s1b = s1a;
        !            61:        iequals(__LINE__, 99, s1b.x);
        !            62:        sna.z = ivalue(98);
        !            63:        snb = sna;
        !            64:        iequals(__LINE__, 98, snb.z);
        !            65: #if ANSI
        !            66:        /* pass to a function and get result of function returning */
        !            67:        s1a = RetS1(s1a);
        !            68:        iequals(__LINE__, 100, s1a.x);
        !            69:        iequals(__LINE__, 100, RetS1(s1a).x);
        !            70:        sna = RetSN(sna);
        !            71:        iequals(__LINE__, 101, sna.z);
        !            72:        iequals(__LINE__, 101, RetSN(sna).z);
        !            73: #endif
        !            74: #if STRUCT_COND_OK
        !            75:        /* copies involving question operators */
        !            76:        i = j = ivalue(0);
        !            77:        s1a.x = ivalue(102);
        !            78:        s1c.x = ivalue(0);
        !            79:        s1b = i ? s1c : (j ? s1c : s1a);
        !            80:        iequals(__LINE__, 102, s1b.x);
        !            81:        sna.z = ivalue(103);
        !            82:        snc.z = ivalue(0);
        !            83:        snb = i ? snc : (j ? snc : sna);
        !            84:        iequals(__LINE__, 103, snb.z);
        !            85: #endif
        !            86: 
        !            87:        /* make sure that structures are passed by value, not by reference */
        !            88:        s1b.x = ivalue(104);
        !            89:        s1a = RetS1(s1b);       /* sets s1a.x to 100 */
        !            90:        iequals(__LINE__, 104, s1b.x);
        !            91:        snb.z = ivalue(104);
        !            92:        sna = RetSN(snb);       /* sets sna.z to 101 */
        !            93:        iequals(__LINE__, 104, snb.z);
        !            94:                {
        !            95:                /* test lvalue use of p->m */
        !            96:                S1 *ps1;
        !            97:                SN *psN = &sna;
        !            98: 
        !            99:                ps1 = &s1b;
        !           100:                ++ps1->x;
        !           101:                iequals(__LINE__, 105, ps1->x);
        !           102:                psN->z++;
        !           103:                iequals(__LINE__, 102, psN->z);
        !           104:                ps1 = s1array;
        !           105:                iequals(__LINE__, 1, (++ps1)->x);
        !           106:                }
        !           107:        }
        !           108:        
        !           109: S1 RetS1(s1)
        !           110:        S1 s1;
        !           111:        {
        !           112:        S1 s1a;
        !           113:        s1a.x = 100;
        !           114:        return(s1a);
        !           115:        }
        !           116: SN RetSN(sn)
        !           117:        SN sn;
        !           118:        {
        !           119:        SN sna;
        !           120:        sna.z = 101;
        !           121:        return(sna);
        !           122:        }
        !           123: 
        !           124: /*
        !           125:  * These tests go into the complexities of interaction between
        !           126:  * question, comma, and structure copies.
        !           127:  */
        !           128: static true = 1;
        !           129: static false = 0;
        !           130: static int Total = 0;
        !           131: 
        !           132: struct mb {
        !           133:        int     mb_i[10];
        !           134:        };
        !           135: struct mb mbr = {0}, mb1 = {1,2}, mb2 = {3,4}, mb3 = {5,6};
        !           136: static int x()
        !           137:        {
        !           138:        Total++;
        !           139:        }
        !           140: 
        !           141: void q_s_a()
        !           142:        {
        !           143:        int i = 1;
        !           144:        do_nothing(&i);
        !           145: 
        !           146: #if STRUCT_COND_OK
        !           147:     mbr = true ? mb1 : mb2;
        !           148:        iequals(__LINE__, mbr.mb_i[i], 2);
        !           149:     mbr = false ? mb1 : mb2;
        !           150:        iequals(__LINE__, mbr.mb_i[i], 4);
        !           151:     mbr = true ? (x(),mb1) : mb2;
        !           152:        iequals(__LINE__, mbr.mb_i[i], 2);
        !           153:     mbr = false ? mb1 : (x(), mb2);
        !           154:        iequals(__LINE__, mbr.mb_i[i], 4);
        !           155:     mbr = true ? (x(),mb1) : (x(),mb2);
        !           156:        iequals(__LINE__, mbr.mb_i[i], 2);
        !           157:     mbr = false ? (x(),mb1) : (x(),mb2);
        !           158:        iequals(__LINE__, mbr.mb_i[i], 4);
        !           159: 
        !           160:        mbr = true ? (mb1=mb2) : mb3;
        !           161:        iequals(__LINE__, mbr.mb_i[i], 4);
        !           162:        iequals(__LINE__, mb1.mb_i[i], 4);
        !           163:        mbr = false ? mb1 : (mb1=mb3);
        !           164:        iequals(__LINE__, mbr.mb_i[i], 6);
        !           165:        iequals(__LINE__, mb1.mb_i[i], 6);
        !           166:        mbr = true ? (mb1=mb2) : (mb1=mb3);
        !           167:        iequals(__LINE__, mbr.mb_i[i], 4);
        !           168:        iequals(__LINE__, mb1.mb_i[i], 4);
        !           169:        mbr = false ? (mb1=mb2) : (mb1=mb3);
        !           170:        iequals(__LINE__, mbr.mb_i[i], 6);
        !           171:        iequals(__LINE__, mb1.mb_i[i], 6);
        !           172: 
        !           173:        mbr = true ? (x(),(mb1=mb2)) : mb3;
        !           174:        iequals(__LINE__, mbr.mb_i[i], 4);
        !           175:        iequals(__LINE__, mb1.mb_i[i], 4);
        !           176:        mbr = false ? mb1 : (x(),(mb1=mb3));
        !           177:        iequals(__LINE__, mbr.mb_i[i], 6);
        !           178:        iequals(__LINE__, mb1.mb_i[i], 6);
        !           179:        mbr = true ? (x(),(mb1=mb2)) : (x(),(mb1=mb3));
        !           180:        iequals(__LINE__, mbr.mb_i[i], 4);
        !           181:        iequals(__LINE__, mb1.mb_i[i], 4);
        !           182:        mbr = false ? (x(),(mb1=mb2)) : (x(),(mb1=mb3));
        !           183:        iequals(__LINE__, mbr.mb_i[i], 6);
        !           184:        iequals(__LINE__, mb1.mb_i[i], 6);
        !           185: 
        !           186:        /* make sure that side effects took place the proper number of times */
        !           187:        iequals(__LINE__, Total, 8);
        !           188: #endif
        !           189:        }
        !           190: 
        !           191: 
        !           192: /*
        !           193:  * UNIONS - try out all of the aggregate things you can do to unions.
        !           194:  */
        !           195: union u1 {
        !           196:        UCHAR u1_c ;
        !           197:        int u1_i;
        !           198:        } u1a, u1b, u1c;
        !           199: 
        !           200: union u2 {
        !           201:        UCHAR u2_c;
        !           202:        int u2_i;
        !           203:        long u2_l;
        !           204:        struct
        !           205:                {
        !           206:                int u2s_a, u2s_b, u2s_c, u2s_d, u2s_e, u2s_f, u2s_g;
        !           207:                } u2_s;
        !           208:        double u2_d;
        !           209:        } u2a, u2b, u2c;
        !           210: 
        !           211: union u1 fu1();
        !           212: union u2 fu2();
        !           213: void vfu1();
        !           214: void vfu2();
        !           215: 
        !           216: void unions()
        !           217:        {
        !           218:        int i = 0;
        !           219: 
        !           220:        u1a.u1_c = 255;
        !           221:        u1b = u1a;
        !           222:        iequals(__LINE__, u1b.u1_c, 255);
        !           223:        u2a.u2_s.u2s_b = -7;
        !           224:        u2b = u2a;
        !           225:        iequals(__LINE__, u2b.u2_s.u2s_b, -7);
        !           226: 
        !           227:        /* check passing by value */
        !           228:        u1a.u1_i = 0;
        !           229:        vfu1(u1a);
        !           230:        iequals(__LINE__, u1a.u1_i, 0);
        !           231:        u2a.u2_d = 0.0;
        !           232:        vfu2(u2a);
        !           233:        dequals(__LINE__, u2a.u2_d, 0.0);
        !           234: #if ANSI
        !           235:        /* check voided return of union */
        !           236:        (void)fu1(0);
        !           237:        (void)fu2(0);
        !           238: #endif
        !           239:        /* check union return and assignment */
        !           240:        u1a = fu1(9);
        !           241:        iequals(__LINE__, u1a.u1_i, 10); 
        !           242:        u2a = fu2(11);
        !           243:        iequals(__LINE__, u2a.u2_s.u2s_g, 12); 
        !           244: #if ANSI
        !           245:        /* check direct access of returned unions */
        !           246:        iequals(__LINE__, fu1(13).u1_i, 14); 
        !           247:        iequals(__LINE__, fu2(15).u2_s.u2s_g, 16);
        !           248: #endif
        !           249:        /* unions involving question operators */
        !           250: #if STRUCT_COND_OK
        !           251:        u1a.u1_c = 17;
        !           252:        u1b.u1_c = 18;
        !           253:        u1c = i ? u1a : u1b;
        !           254:        iequals(__LINE__, u1c.u1_c, 18);
        !           255:        u2a.u2_s.u2s_g = 19;
        !           256:        u2b.u2_s.u2s_g = 20;
        !           257:        u2c = i ? u2a : u2b;
        !           258:        iequals(__LINE__, u2c.u2_s.u2s_g, 20);
        !           259: #endif
        !           260:        }
        !           261: 
        !           262: union u1 fu1(i)
        !           263:        int i;
        !           264:        {
        !           265:        static union u1 u;
        !           266:        u.u1_i = i+1;
        !           267:        return u;
        !           268:        }
        !           269: 
        !           270: union u2 fu2(i)
        !           271:        int i;
        !           272:        {
        !           273:        static union u2 u;
        !           274:        u.u2_s.u2s_g = i+1;
        !           275:        return u;
        !           276:        }
        !           277: 
        !           278: /* set i field of passed in union */
        !           279: void vfu1(u)
        !           280:        union u1 u;
        !           281:        {
        !           282:        u.u1_i = 99;
        !           283:        }
        !           284: 
        !           285: /* set d field of passed in union */
        !           286: void vfu2(u)
        !           287:        union u2 u;
        !           288:        {
        !           289:        u.u2_d = 99.99;
        !           290:        }
        !           291: #endif
        !           292: 
        !           293: #else /* if SKIP33C */
        !           294: 
        !           295: void structures() { pr_skip("c3_3c (structures): SKIPPED ENTIRELY\n"); }
        !           296: #endif /* SKIP33C */
        !           297: 

unix.superglobalmegacorp.com

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