view test/bitfield1.c @ 449:c55363eff5e5

parallel assignment (modify not completed)
author kono
date Thu, 25 Nov 2004 16:56:26 +0900
parents 61c77ff18023
children 32737bad7489
line wrap: on
line source


   struct aho {
        int i:1,j:1;
        char a:7;
        char :7,k:1,:3;
	long long v:33;
	long long w:33;
	long long x:33;
   } a /* = {-1,3,3,3,3} */ ;

   union aho1 {
        int i:1,j:1;
        char a:7;
        char :7,k:1,:3;
	long long v:33;
	long long w:33;
	long long x:33;
   } a11 ;

union ll1 {
   unsigned char a[32];
   struct {
        char a:4;
	long long v:33;
	long long w:33;
	long long x:33;
   } b;
} ll1;

union ll0 {
   unsigned char a[32];
   struct {
        char a:4;
	long long v:48;
	long long w:48;
	long long x:48;
   } b;
} ll0;


union ll {
   unsigned char a[32];
   struct {
        char a:4;
	long long v:56;
	long long w:56;
	long long x:56;
   } b;
} ll;

union cc {
   int a;
   struct {
	char a:1;
	char b:4;
	char c:7;
	char d:4;
	char e:4;
	char f:4;
   } b;
} cc;

union ii {
   int a;
   struct {
	int a:1;
	int b:4;
	int c:4;
	int d:4;
	int e:4;
	int f:4;
    } b;
} ii;

main()
{
    int i;
    printf("#0077:%d\n",a.i);

     ll1.b.v = -1;
     printf("#0080:01:%llx\n",ll1.b.v);
     printf("#0081:02:"); for(i=0;i<32;i++) printf("%02x",ll1.a[i]); printf("\n");
     ll1.b.v = 0;
     ll1.b.w = -1;
     printf("#0084:02:"); for(i=0;i<32;i++) printf("%02x",ll1.a[i]); printf("\n");
     ll1.b.w = 0;
     ll1.b.x = -1;
     printf("#0087:02:"); for(i=0;i<32;i++) printf("%02x",ll1.a[i]); printf("\n");

     ll0.b.v = -1;
     printf("#0090:01:%llx\n",ll0.b.v);
     printf("#0091:02:"); for(i=0;i<32;i++) printf("%02x",ll0.a[i]); printf("\n");
     ll0.b.v = 0;
     ll0.b.w = -1;
     printf("#0094:02:"); for(i=0;i<32;i++) printf("%02x",ll0.a[i]); printf("\n");
     ll0.b.w = 0;
     ll0.b.x = -1;
     printf("#0097:02:"); for(i=0;i<32;i++) printf("%02x",ll0.a[i]); printf("\n");

     ll.b.v = -1;
     printf("#0100:1:%llx\n",ll.b.v);
     printf("#0101:02:"); for(i=0;i<32;i++) printf("%02x",ll.a[i]); printf("\n");
     ll.b.v = 0;
     ll.b.w = -1;
     printf("#0104:02:"); for(i=0;i<32;i++) printf("%02x",ll.a[i]); printf("\n");
     ll.b.w = 0;
     ll.b.x = -1;
     printf("#0107:02:"); for(i=0;i<32;i++) printf("%02x",ll.a[i]); printf("\n");

     printf("#0109:char a:1; char b:4; char c:7; char d:4; char e:4; char f:4;\n");
     cc.b.a = -1;
     printf("#0111:a:%08x\n",cc.a);
     cc.b.b = -1;
     printf("#0113:b:%08x\n",cc.a);
     cc.b.c = -1;
     printf("#0115:c:%08x\n",cc.a);
     cc.b.d = -1;
     printf("#0117:d:%08x\n",cc.a);
     cc.b.e = -1;
     printf("#0119:e:%08x\n",cc.a);
     cc.b.f = -1;
     printf("#0121:f:%08x\n",cc.a);
     printf("#0122:3:%d %d\n",cc.b.c,cc.b.d);
     cc.a = -1;
     printf("#0124:f:%08x\n",cc.a);
     cc.b.a = 0;
     printf("#0126:a:%08x\n",cc.a);
     cc.b.b = 0;
     printf("#0128:b:%08x\n",cc.a);
     cc.b.c = 0;
     printf("#0130:c:%08x\n",cc.a);
     cc.b.d = 0;
     printf("#0132:d:%08x\n",cc.a);
     cc.b.e = 0;
     printf("#0134:e:%08x\n",cc.a);
     cc.b.f = 0;
     printf("#0136:f:%08x\n",cc.a);
     printf("#0137:3:%d %d\n",cc.b.c,cc.b.d);
     cc.a = 0;
     printf("#0139:f:%08x\n",cc.a);
     cc.b.a = 1;
     printf("#0141:a:%08x\n",cc.a);
     cc.b.b = 1;
     printf("#0143:b:%08x\n",cc.a);
     cc.b.c = 1;
     printf("#0145:c:%08x\n",cc.a);
     cc.b.d = 1;
     printf("#0147:d:%08x\n",cc.a);
     cc.b.e = 1;
     printf("#0149:e:%08x\n",cc.a);
     cc.b.f = 1;
     printf("#0151:f:%08x\n",cc.a);
     printf("#0152:3:%d %d\n",cc.b.c,cc.b.d);
     cc.a = -1;
     printf("#0154:f:%08x\n",cc.a);
     cc.b.a = 1;
     printf("#0156:a:%08x\n",cc.a);
     cc.b.b = 1;
     printf("#0158:b:%08x\n",cc.a);
     cc.b.c = 1;
     printf("#0160:c:%08x\n",cc.a);
     cc.b.d = 1;
     printf("#0162:d:%08x\n",cc.a);
     cc.b.e = 1;
     printf("#0164:e:%08x\n",cc.a);
     cc.b.f = 1;
     printf("#0166:f:%08x\n",cc.a);
     printf("#0167:3:%d %d\n",cc.b.c,cc.b.d);

     ii.b.a = -1;
     printf("#0170:6:%08x\n",ii.a);
     ii.b.d = -1;
     printf("#0172:6:%08x\n",ii.a);
     printf("#0173:5:%d %d\n",ii.b.a,ii.b.d);

    main5();
    return 0;
}


main5()
{
    int i,j,bit=1;
    for(i=0;i<32;i++,bit<<=1) {
	ii.a = bit;
	printf("#0185:%08x:ii.b.a=%d ii.b.b=%d ii.b.c=%d ii.b.d=%d ii.b.e=%d ii.b.f=%d\n",bit,
		ii.b.a,ii.b.b,ii.b.c,ii.b.d,ii.b.e,ii.b.f);
    }
    bit=1;
    for(i=0;i<32;i++,bit<<=1) {
	cc.a = bit;
	printf("#0191:%08x:cc.b.a=%d cc.b.b=%d cc.b.c=%d cc.b.d=%d cc.b.e=%d cc.b.f=%d\n",bit,
		cc.b.a,cc.b.b,cc.b.c,cc.b.d,cc.b.e,cc.b.f);
    }
    ll.a[0]=ll.a[1]=ll.a[2]=ll.a[3]= ll.a[4]=ll.a[5]=ll.a[6]=ll.a[7]=0;
        ll.b.v=ll.b.w=ll.b.x = 0;
    for(i=7;i>=0;i--) {
    bit=1;
	for(j=0;j<32;j++,bit<<=1) {
	    ll.a[i] = bit;
	     printf("#0200:02:%08x %08x %08x %08x %08x %08x %08x %08x\n",
		ll.a[0],ll.a[1],ll.a[2],ll.a[3],
		ll.a[4],ll.a[5],ll.a[6],ll.a[7]
	      );
	    printf("#0204: ll.b.v=%lld ll.b.w=%lld ll.b.x=%lld\n",ll.b.v,ll.b.w,ll.b.x);
	}
	ll.a[i]=0;
    }
}