国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
union深度探索
typdef union {
       int n;
       char c;
} NC;

nc.c   確實(shí)有 *(char *)&nc   的意思
nc.n 確實(shí)有 *(int *)&nc     的意思
(存取方式)

我覺得,可以用union去描述同一概念,但不會同時出現(xiàn)的東西。
比如
union mark
{
int score;
char grade;
}

寫程序時,別人比較容易理解;改的時候也容易。

The primary usefulness of a union is to conserve space, since it provides a way of letting many different types be stored in the same space. Unions also provide crude polymorphism. However, there is no checking of types, so it is up to the programmer to be sure that the proper fields are accessed in different contexts. The relevant field of a union variable is typically determined by the state of other variables, possibly in an enclosing struct.
(union常不是單獨(dú)使用,而是與struct一起,它的值常是由密封在struct中的其他變量的狀態(tài)決定的)


舉個例子:
[php]
struct in6_addr
   {
union
   {
       uint8_t u6_addr8[16];
       uint16_t u6_addr16[8];
       uint32_t u6_addr32[4];
   } in6_u;
#define s6_addr                 in6_u.u6_addr8
#define s6_addr16             in6_u.u6_addr16
#define s6_addr32             in6_u.u6_addr32
   };
[/php]

uinion在協(xié)議里用的很多

本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C語言中Union類型的使用方法
由 serverAdd.sin_addr.s_addr 引發(fā)的思考
用libnet和libpcap構(gòu)建Linux下的SYN掃描程序
in.h
C/C++結(jié)構(gòu)體內(nèi)存粒度對齊?結(jié)合調(diào)試信息來看
NTP協(xié)議實(shí)現(xiàn)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服