C????λ????ü??????????
?????zhenhuaqin ???????[ 2016/12/20 14:03:14 ] ????????λ?? .NET
??????ν“λ??”??????????е????λ???????????????????????????????λ??????????????????????????????а????????в???????????????????????????????????????λ?????????λ???????λ??????????λ?????????????£?????????
????struct λ?????
????{ λ???б? };
????eg??
struct weiyu {
int a:2;
int b:5;
int :5;//????λ????????????
int c:3;
}
????λ????????????????????????
????1) ???????λ????ε??????????????λ?????С???????sizeof??С??????????
?????ν???????????δ洢?????????????????
????2) ???????λ????ε??????????????λ?????????????sizeof??С??????????
?????ν????μ?洢???????????????????????С??????????
????3) ????????????С??????????????С??????????
????4) ????????λ????ε???????????????????????????в???VC6??????????
???????Dev-C++???????????
????5) ???λ?????????????λ????Σ??????????????????????е????????
????4 ??5?????????н?????????????????????????
#include "stdio.h"
void main(int argn ??char *argv)
{
struct test {
unsigned a:10;
unsigned b:10;
unsigned c:6;
unsigned :2;//this two bytes can't use
unsigned d:4;
}data??*pData;
data.a=0x177;
data.b=0x111;
data.c=0x7;
data.d=0x8;
pData=&data;
printf("data.a=%x data.b= %x data.c=%x data.d=%xn"??pData->a??pData->b??pData->c??pData->d);//λ???????????
printf("sizeof(data)=%dn"??sizeof(data)); //4 bytes ??????????
struct testLen{
char a:5;
char b:5;
char c:5;
char d:5;
char e:5;
}len;
printf("sizeof(len)=%dn"??sizeof(len)); //5bytes ????2
struct testLen1{
char a:5;
char b:2;
char d:3;
char c:2;
char e:7;
}len1;
printf("sizeof(len1) =%dn"??sizeof(len1)); //3bytes ????1
struct testLen2{
char a:2;
char :3;
char b:7;
long d:20; //4bytes
char e:4;
}len2;
printf("sizeof(len2)=%dn"??sizeof(len2)); //12 ????3??4??5??????4??????????2+3 ?1byte??b?1bye ??????long????2+3+7 ?4???????? d ?? e????????? ????4???
struct testLen3{
char a:2;
char :3;
char b:7;
long d:30;
char e:4;
}len3;
printf("sizeof(len3)=%dn"??sizeof(len3));//12 ????3??4??5??????4??????????2+3 ?1byte??b?1bye ??????long????2+3+7 ?4???????? d????4???????????long????e??????4???
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11