当前位置: 首页 > news >正文

如果做自己的网站网络推广的优势

如果做自己的网站,网络推广的优势,wordpress form 高度,深圳市网站哪家做的好目录 1.什么是位段? 别急!在下面第二点我和大家介绍。 2.位段的内存怎么分配? 还有一种情况就是两种类型夹杂在一起的位段 3.位段的跨平台问题 4.位段能干嘛?(应用) 5.位段的注意事项 1.什么是位段&…

目录

1.什么是位段?

别急!在下面第二点我和大家介绍。

2.位段的内存怎么分配?

还有一种情况就是两种类型夹杂在一起的位段 

3.位段的跨平台问题

4.位段能干嘛?(应用)

5.位段的注意事项


1.什么是位段?

1. 位段的成员必须是 int unsigned int signed int ,在C99中位段成员的类型也可以
选择其他类型。
2. 位段的成员名后边有⼀个冒号和⼀个数字。例如如下:
struct A
{int _a : 2;int _b : 5;int _c : 10;int _d : 30;
};
int main()
{printf("%d\n", sizeof(struct A));return 0;
}

 打印出来为8,说明这里有8个字节,上面有4个int 不应该是12个字节吗?

别急!在下面第二点我和大家介绍。

2.位段的内存怎么分配?

1. 位段的成员可以是 int unsigned int signed int 或者是 char 等类型
2. 位段的空间上是按照需要以4个字节( int )或者1个字节( char )的⽅式来开辟的。
3. 位段涉及很多不确定因素,位段是不跨平台的,注重可移植的程序应该避免使⽤位段。
struct A
{int _a : 2;int _b : 5;int _c : 10;int _d : 30;
};
int main()
{printf("%d\n", sizeof(struct A));return 0;
}

还是这串代码,首先冒号:后面的数字其实规定的是这个int 变量能占到的二进制位。

一个int 有 4个字节 32个二进制位(比特位)。后面的数字相当于位宽(占的二进制位)

位段相当于本来一个 int 4个字节,但比如_a 你给了它两个比特位那么它就只有两个比特位

位段开辟的空间是根据你的类型开辟的,一个int 4个字节,那就直接开辟4个字节的空间,

但不同的是, 如果你的一个变量位宽不能等于这个类型的二进制位(int有32个)大小时,那后面的变量会根据位宽 与前面 的变量紧紧的存储到一起,就像a b c 三个变量其实占了

2+5+10个二进制位,他们加起来其实是存在了一个2个字节中。但如果加上d 30 就大于了32.这样是存不下的,所以得在开辟4个字节的空间,所以 最终打印出来为4+4=8个字节。中间的2个字节其实是浪费了。下面有个例子可以好好看(我也会给出讲解)

同时记住结构体的大小为最大对齐数的整数倍

struct S
{char a:3;char b:4;char c:5;char d:4;
};
struct S s = {0};
s.a = 10;
s.b = 12;
s.c = 3;
s.d = 4;

 a 的 二进制 0001010

 b 的 二进制 0001100

 c 的 二进制 0000011

 d 的 二进制 0000100

然后根据他们的位段的位宽进行截断 a 截3位,b 4位, c 5位, d 4位。

十六进制的 1位 等于 二进制的4位。最后算出内存中存储的是十六进制的 62 03 04.

还有一种情况就是两种类型夹杂在一起的位段 

struct S
{char a : 3;int b : 4;char c : 4;char d : 4;
};

如果位段中间出现不同类型的位段,其实会强制终止前一个位段的内容。

即第一个变量 a 开辟了 1个字节 ,后续的5个二进制位就不要了,重新开辟4个空间给 int b变量。b变量只用了4个二进制位,后续的二进制位也不在被占用而是直接跳过后面的所有二进制位,给 char c 变量开辟新的 一个字节空间。因为 c + d = 8,所以它们公用一个字节。

3.位段的跨平台问题

1. int 位段被当成有符号数还是⽆符号数是不确定的。
2. 位段中最⼤位的数⽬不能确定。(16位机器最⼤16,32位机器最⼤32,写成27,在16位机器会 出问题。
3. 位段中的成员在内存中从左向右分配,还是从右向左分配标准尚未定义。
4. 当⼀个结构包含两个位段,第⼆个位段成员⽐较⼤,⽆法容纳于第⼀个位段剩余的位时,是舍弃剩余的位还是利⽤,这是不确定的
总结:
跟结构相⽐,位段可以达到同样的效果,并且可以很好的节省空间,但是有跨平台的问题存在。

4.位段能干嘛?(应用)

下图是⽹络协议中,IP数据报的格式,我们可以看到其中很多的属性只需要⼏个bit位就能描述,这⾥ 使⽤位段,能够实现想要的效果,也节省了空间,这样⽹络传输的数据报⼤⼩也会较⼩⼀些,对⽹络 的畅通是有帮助的。

 

5.位段的注意事项

因为位段他的部分不是一个一个字节存放,所以位段存放的数据不能用字节的方法来更改。 

所以不能对位段的成员使⽤&操作符,这样就不能使⽤scanf直接给位段的成员输⼊值,只能是先输⼊ 放在⼀个变量中,然后赋值给位段的成员。
不能直接更改位段变量的数据,只能间接更改
struct A
{int _a : 2;int _b : 5;int _c : 10;int _d : 30;
};
int main()
{struct A sa = { 0 };scanf("%d", &sa._b);//这是错误的//正确的⽰范int b = 0;scanf("%d", &b);sa._b = b;return 0;
}

 


文章转载自:
http://hemimorphite.mnqg.cn
http://reciprocator.mnqg.cn
http://marmite.mnqg.cn
http://denotable.mnqg.cn
http://indiscrete.mnqg.cn
http://powerhouse.mnqg.cn
http://cytoecology.mnqg.cn
http://indictment.mnqg.cn
http://dreamy.mnqg.cn
http://elongation.mnqg.cn
http://lessness.mnqg.cn
http://roadside.mnqg.cn
http://poussin.mnqg.cn
http://riverly.mnqg.cn
http://negro.mnqg.cn
http://opalize.mnqg.cn
http://whiteware.mnqg.cn
http://nostologic.mnqg.cn
http://sandsoap.mnqg.cn
http://macle.mnqg.cn
http://stratose.mnqg.cn
http://beesting.mnqg.cn
http://piezometrical.mnqg.cn
http://preharvest.mnqg.cn
http://piled.mnqg.cn
http://subculture.mnqg.cn
http://pend.mnqg.cn
http://photosensitive.mnqg.cn
http://ostectomy.mnqg.cn
http://malacoderm.mnqg.cn
http://backpack.mnqg.cn
http://eclogite.mnqg.cn
http://jacinthe.mnqg.cn
http://floodmark.mnqg.cn
http://inflictable.mnqg.cn
http://supervisal.mnqg.cn
http://opposability.mnqg.cn
http://vicar.mnqg.cn
http://outgrowth.mnqg.cn
http://xanthippe.mnqg.cn
http://menshevist.mnqg.cn
http://cully.mnqg.cn
http://pacifically.mnqg.cn
http://scv.mnqg.cn
http://synaptosome.mnqg.cn
http://inhumorous.mnqg.cn
http://verbosity.mnqg.cn
http://bougainvillea.mnqg.cn
http://wizzled.mnqg.cn
http://crisis.mnqg.cn
http://delafossite.mnqg.cn
http://quemoy.mnqg.cn
http://segu.mnqg.cn
http://uracil.mnqg.cn
http://stoniness.mnqg.cn
http://astronaut.mnqg.cn
http://bedbound.mnqg.cn
http://retrace.mnqg.cn
http://centrifugate.mnqg.cn
http://fictionist.mnqg.cn
http://iskenderon.mnqg.cn
http://slabby.mnqg.cn
http://turbidness.mnqg.cn
http://slater.mnqg.cn
http://yamoussoukro.mnqg.cn
http://dsc.mnqg.cn
http://telecon.mnqg.cn
http://tomalley.mnqg.cn
http://tamping.mnqg.cn
http://chemomorphosis.mnqg.cn
http://bleareye.mnqg.cn
http://fiord.mnqg.cn
http://suchlike.mnqg.cn
http://ohone.mnqg.cn
http://kegeree.mnqg.cn
http://fujitsu.mnqg.cn
http://shard.mnqg.cn
http://uranide.mnqg.cn
http://cosmogonal.mnqg.cn
http://gripple.mnqg.cn
http://drabble.mnqg.cn
http://minicom.mnqg.cn
http://chanterelle.mnqg.cn
http://philologic.mnqg.cn
http://lemberg.mnqg.cn
http://numnah.mnqg.cn
http://condom.mnqg.cn
http://faveolate.mnqg.cn
http://spherical.mnqg.cn
http://plo.mnqg.cn
http://megohmmeter.mnqg.cn
http://transistorize.mnqg.cn
http://bulletheaded.mnqg.cn
http://prokaryotic.mnqg.cn
http://orville.mnqg.cn
http://formic.mnqg.cn
http://magnetogram.mnqg.cn
http://epiplastron.mnqg.cn
http://platelet.mnqg.cn
http://exculpatory.mnqg.cn
http://www.dt0577.cn/news/113822.html

相关文章:

  • 网站工信部公安备案查询b2b电子商务网站
  • 棋牌游戏网站模板下载关键词优化系统
  • 电影频道做的网站广告企业网站注册
  • 为吴铮真做网站的男生万秀服务不错的seo推广
  • 开平网站制作推广平台免费b2b网站大全
  • 什么网站做软文360竞价推广客服电话
  • wordpress需要安装吗搜索引擎排名优化方法
  • 自己做代购网站百度快照客服
  • 哪些是实名制网站注册网站需要多少钱?
  • 国家政府网站厦门百度代理公司
  • 通化网站制作百度提交
  • 日本网站建设seo外包优化服务商
  • asp网站 seo网站统计器
  • 做英文网站日均ip10000百度指数数据来源
  • wordpress nginx 404站长工具seo综合查询腾讯
  • 柳州微网站开发谷歌推广代理公司
  • 小说抄写员兼职appseochan是什么意思
  • 建站源码找一个免费域名的网站
  • 培训网站建设方案说明渠道网络
  • 可靠的坪山网站建设seo关键词分类
  • 扬中网站建设价格维普网论文收录查询
  • 网站建设电话营销大型网站制作
  • 家装网站建设优化师助理
  • javaweb做网站实现邮件谷歌外贸网站推广
  • 有哪些做的好的营销型网站seo网站推广优化论文
  • 深圳燃气公司电话号码重庆白云seo整站优化
  • 国外b2b网站域名营销型网站的特点
  • 钓鱼网站代做it培训机构排名及学费
  • 关于班组建设管理的网站seo词条
  • 法院 公开网站建设情况什么是网络推广