Annotation of researchv10no/cmd/cfront/szal2.1.c, revision 1.1

1.1     ! root        1: /*ident        "@(#)ctrans:szal.c      1.4.1.2" */
        !             2: /*******************************************************************
        !             3: 
        !             4:        Copyright (c) 1986 AT&T, Inc. All Rights Reserved
        !             5:        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T, INC.
        !             6: 
        !             7: szal.c:
        !             8: 
        !             9:        C program to run on a machine to write a size/align file for
        !            10:        the C++ translator.
        !            11: 
        !            12:        Most output line are on the form:
        !            13:                typeX   sizeof(typeX)   alignment_requirement_for_typeX
        !            14:        assumes
        !            15: 
        !            16:           -    that ``double d0; char c0;'' poses the worst alignment condition
        !            17:           -    two's complement integer representation
        !            18:           -    that a word is defined by a :0 field
        !            19: 
        !            20: *****************************************************************************/
        !            21: 
        !            22: #include <stdio.h>
        !            23: 
        !            24: typedef int (*PF)();
        !            25: struct st1 { char a; };
        !            26: struct ss {
        !            27:        double a0; char c0;
        !            28:        char c1;
        !            29:        double a00; char c00;
        !            30:        short s1;
        !            31:        double a2; char c2;
        !            32:        int i1;
        !            33:        double a3; char c3;
        !            34:        long l1;
        !            35:        double a4; char c4;
        !            36:        float f1;
        !            37:        double a6; char c5;
        !            38:        double d1;
        !            39:        double a7; char c6;
        !            40:        char* p1;
        !            41:        double a8; char c7;
        !            42:        struct ss * p2;
        !            43:        double a9; char c8;
        !            44:        struct st1 oo;
        !            45:        double a10; char c9;
        !            46:        PF pf;
        !            47: } oo;
        !            48: struct st5 { char a; int :0; };        /* by definition: a word */
        !            49: struct st2 { char :2; };
        !            50: struct st3 { int :2; };
        !            51: struct st4 { char :2; char :2; };
        !            52: 
        !            53: struct st6 { char v[3]; char : 2; };   /* fits in 4 bytes */
        !            54: struct st7 { char v[3]; int : 2; };    /* might not */
        !            55: struct st8 { char v[3]; char : 2; char : 2; };
        !            56: 
        !            57: struct st9 { char v[7]; char : 2; };   /* fits in 8 bytes */
        !            58: struct st10 { char v[7]; int : 2; };   /* might not */
        !            59: struct st11 { char v[7]; char : 2; char : 2; };
        !            60: 
        !            61: out(s,a1) char* s; int a1;
        !            62: {
        !            63:        printf("%s %d\n",s,a1);
        !            64: }
        !            65: 
        !            66: outstr(s,str2) char* s; char* str2;
        !            67: {
        !            68:        printf("%s \"%s\"\n",s,str2);
        !            69: }
        !            70: 
        !            71: int a123456789 = 1;    /* if this does not compile get a better C compiler */
        !            72: int a123456780 = 2;
        !            73: 
        !            74: 
        !            75: main()
        !            76: {
        !            77:        char largest[50];
        !            78:        char c = 1;
        !            79:        int i1 = 0;
        !            80:        int i2 = 0;
        !            81:        long i = 1L;
        !            82:        unsigned int    large;
        !            83: 
        !            84:        if (a123456789 == a123456780)
        !            85:                fprintf(stderr,"Warning: Your C compiler is dangerous.\nIt strips trailing characters off long identifiers without warning.\nGet a new one\n");
        !            86: 
        !            87:        while (c) { c<<=1; c&=~1; i1++; }       /* i1 = #bits in byte */
        !            88: 
        !            89:        if (sizeof(struct st5) == sizeof(char)) /* i2 = #bits in word  */
        !            90:                i2 = i1;
        !            91:        else if (sizeof(struct st5) == sizeof(short)) {
        !            92:                short i = 1;
        !            93:                while (i) { i<<=1; i&=~1; i2++; }
        !            94:        }
        !            95:        else if (sizeof(struct st5) == sizeof(int))
        !            96:                while (i) { i<<=1; i&=~1; i2++; }
        !            97:        else if (sizeof(struct st5) == sizeof(long)) {
        !            98:                long i = 1;
        !            99:                while (i) { i<<=1; i&=~1; i2++; }
        !           100:        }
        !           101:        else {
        !           102:                fprintf(stderr,"Warning: Your C compiler probably handles 0 lengths fields wrong\n");
        !           103:                i = sizeof(int);
        !           104:        }
        !           105: 
        !           106:        out("#define DBI_IN_WORD",i2);
        !           107:        out("#define DBI_IN_BYTE",i1);
        !           108:        out("#define DSZ_CHAR",sizeof(char));
        !           109:        out("#define DAL_CHAR",(int)&oo.c1-(int)&oo.c0);
        !           110:        out("#define DSZ_SHORT",sizeof(short));
        !           111:        out("#define DAL_SHORT",(int)&oo.s1-(int)&oo.c00);
        !           112:        out("#define DSZ_INT",sizeof(int));
        !           113:        out("#define DAL_INT",(int)&oo.i1-(int)&oo.c2);
        !           114:        out("#define DSZ_LONG",sizeof(long));
        !           115:        out("#define DAL_LONG",(int)&oo.l1-(int)&oo.c3);
        !           116:        out("#define DSZ_FLOAT",sizeof(float));
        !           117:        out("#define DAL_FLOAT",(int)&oo.f1-(int)&oo.c4);
        !           118:        out("#define DSZ_DOUBLE",sizeof(double));
        !           119:        out("#define DAL_DOUBLE",(int)&oo.d1-(int)&oo.c5);
        !           120:        /*  next two should just be repeats of above two */
        !           121:        out("#define DSZ_LDOUBLE",sizeof(double));
        !           122:        out("#define DAL_LDOUBLE",(int)&oo.d1-(int)&oo.c5);
        !           123:        i = 1<<(sizeof(char*)*i1-2); 
        !           124:        if (i<400*1024L)
        !           125:                fprintf(stderr,"Pointers to data too small to handle C++\n");
        !           126: 
        !           127:        i = 1<<(sizeof(PF)*i1-2); 
        !           128:        if (i<250*1024L)
        !           129:                fprintf(stderr,"Pointers to functions too small to handle C++\n");
        !           130:        /* out("fptr",sizeof(PF),(int)&oo.pf-(int)&oo.c9,0); */
        !           131:        if (sizeof(PF)!=sizeof(struct ss*))
        !           132:                fprintf(stderr,"Cannot handle sizeof(pointer to function) != sizeof(pointer to struct)\n");
        !           133:        out("#define DSZ_STRUCT",sizeof(struct st1));
        !           134:        out("#define DAL_STRUCT",(int)&oo.oo-(int)&oo.c8);
        !           135:        out("#define DSZ_WORD",sizeof(struct st5));
        !           136:        out("#define DSZ_WPTR",sizeof(struct ss *));
        !           137:        out("#define DAL_WPTR",(int)&oo.p2-(int)&oo.c7);
        !           138:        out("#define DSZ_BPTR",sizeof(char*));
        !           139:        out("#define DAL_BPTR",(int)&oo.p1-(int)&oo.c6);
        !           140:        large = (unsigned)~0;
        !           141:        large = large >> 1;
        !           142:        sprintf(largest,"%d",large);    /* largest integer */
        !           143:        outstr("#define DLARGEST_INT",largest);
        !           144:        switch (sizeof(struct st1)) {
        !           145:        case 1:
        !           146:                i1 = sizeof(struct st2)!=sizeof(struct st3);
        !           147:                i2 = sizeof(struct st2)==sizeof(struct st4);
        !           148:                break;
        !           149:        case 2:
        !           150:                i1 = sizeof(struct st6)!=sizeof(struct st7);
        !           151:                i2 = sizeof(struct st6)==sizeof(struct st8);
        !           152:                break;
        !           153:        case 4:
        !           154:                i1 = sizeof(struct st9)!=sizeof(struct st10);
        !           155:                i2 = sizeof(struct st9)==sizeof(struct st11);
        !           156:                break;
        !           157:        default:
        !           158:                fprintf(stderr,"Cannot figure out if field sizes are sensitive to the type of fields\n");
        !           159:        }
        !           160:        out("#define DF_SENSITIVE",i1); /* sensitive to field type */
        !           161:        out("#define DF_OPTIMIZED",i2); /* packs fields */
        !           162: }

unix.superglobalmegacorp.com

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