当前位置:网站首页>[advanced C language] special user-defined type
[advanced C language] special user-defined type
2022-06-30 00:12:00 【Haozai lives today】
List of articles
1、 Bit segment
1.1、 What is a bit segment
1、 The member of the segment must be int、unsigned int 、 signed int or char It belongs to the integer family .
2、 There is a colon and a number after the member name of the bit segment
3、 The function of bit segment is to save memory space 
1.2、 Bit segment memory allocation
1、 The space of the bit segment is as needed in 4 Bytes (int), perhaps 1 Bytes (char) The way to open up .
2、 There are many uncertainties in the bit segment , Therefore, bit segments are not cross platform ( Focus on portable programs Bit segments should be avoided )
1.3、 The cross platform problem of bit segment
1、int It's uncertain whether a bit segment is treated as a signed number or an unsigned number
2、 The number of the largest bits in the bit segment cannot be determined (32 The machine is the largest 32,64 The machine is the largest 64)
3、 The members in the bit segment are allocated from left to right in memory , Or right to left allocation criteria have not yet been defined
4、 When a structure contains two bit segments , The second segment is relatively large , Cannot hold the remaining bits of the first bit segment , Whether to discard the remaining bits or to use , This is uncertain
2、 enumeration
1、 Enumeration is a List , List all the possibilities
such as :
One 、 There are seven days in a week , Monday to Sunday can be enumerated
Two 、 Month has 12 Months , January to December can be enumerated
wait
2.1、 Definition of enumeration type
1、 Enumeration is a special custom type
2、 The enumerated quantities are Constant
enum Day// Enumerate the days of the week
{
// Possible values of enumeration
Mon = 1,// Give Way Mon be equal to 1 The operation of , Is to assign an initial value to an enumeration constant , Does not mean that the enumeration is a variable
Tues,
Wed,
Thur,
Fri,
Sta,
Sun
};
enum Sex// Enumerate gender
{
MALE,
FEMALE,
SECRET
};
int main()
{
enum Day d = Sun;
enum Sex s = SECRET;
return 0;
}
2.2、 Advantages of enumeration
1、 Increase the readability and maintainability of the code
2、 and #define Defined identifier comparison , Enumeration has type checking , More rigorous
3、 Prevent naming pollution
4、#define Unable to debug , Enumeration can be debugged
3、 union ( Shared body )
1、 Federation is also a special custom type
2、 Variables defined by this type also contain a series of members , The feature is that these members share a space
3、 The members of the consortium share a memory space , The size of such a joint variable , At least the size of the largest member .( The consortium needs to be able to keep the largest members )
4、 Use cases 
5、 Use the union to judge the byte order of large and small ends
cheak_sys()
{
union Un
{
char c;
int i;
}u;
u.i = 1;
return u.c;
}
int main()
{
int ret = cheak_sys();
if (1 == ret)
printf(" The small end \n");
else
printf(" Big end \n");
// If you return 1, Indicates the small endian byte order
// If you return 0, Indicates the big endian byte order
return 0;
}
3.1、 Calculation of the size of the consortium
1、 The size of the consortium is at least the largest member .
2、 When the maximum member size is not an integral multiple of the maximum number of alignments , It's about aligning to an integer multiple of the maximum number of alignments
边栏推荐
- Activity invitation | the Apache Doris community essay and speech solicitation activity has begun!
- Color space conversion in video tonemapping (HDR to SDR) (bt2020 to bt709, YCbCr, YUV and RGB)
- Summary of DOM knowledge points
- 视频ToneMapping(HDR转SDR)中的颜色空间转换问题(BT2020转BT709,YCbCr、YUV和RGB)
- How long will it take to open a mobile account? In addition, is it safe to open a mobile account?
- Cloud native enthusiast weekly: cool collection of grafana monitoring panels
- Web APIs environment object - dark horse programmer
- ThinkPad VMware installation virtual machine: this host supports Intel VT-x, but Intel VT-x is disabled (problem resolution)
- Solr基础操作7
- 代码分析平台 SonarQube 实战
猜你喜欢

Construction of module 5 of actual combat Battalion

Serialization of binary tree 297 Serialization and deserialization of binary tree 652 Find duplicate subtrees

Zhongkang holdings opens the offering: it plans to raise HK $395million net, and it is expected to be listed on July 12

Siemens low code platform connects MySQL through database connector to realize addition, deletion, modification and query

Unity splashimage scaling problem
![Majority element ii[molar voting method for finding modes]](/img/8f/5925f97c0f5f8c50c19a9ef6d7723c.png)
Majority element ii[molar voting method for finding modes]

QT learning 01 GUI program principle analysis

FPGA Development (2) -- IIC communication
![[Shangshui Shuo series] day 8](/img/66/2aaa82f122612db1775bdd45556d97.png)
[Shangshui Shuo series] day 8

由GlideException: Failed DecodePath{DirectByteBuffer->GifDrawable->Drawable}引起的刨根问底
随机推荐
How to view the CPU cores and threads in win11? Win11 view the tutorial of how many cores and threads the CPU is
Solr基础操作9
Halcon practical: design idea of solder joint detection
西门子低代码 9.14版本: 满足不同需求
Code analysis platform sonarqube actual combat
【微信小程序】认识小程序项目的基本组成结构
Solr basic operations 14
利用 CertBot 申请 Let’s Encrypt SSL 证书
Basic tutorial for installing monggodb in win10
333333333333333333333333333333
这次的PMP考试(6月25日),有人欢喜有人忧,原因就在这...
Set up enterprise NTP time server
MySQL multi table query
Root cause of glideexception: failed decodepath{directbytebuffer- > gifdrawable- > drawable}
vsftp 与 TFTP 与 samba 与 nfs 复习
QT learning 07 coordinate system in QT
Label Troubleshooting: unable to open the marked image
Stack space of JVM
Color space conversion in video tonemapping (HDR to SDR) (bt2020 to bt709, YCbCr, YUV and RGB)
克隆無向圖[bfs訪問每條邊而不止節點]