当前位置:网站首页>Interpretation of C basic syntax: summarize some commonly used but easily confused functions (i++ and ++i) in the program (bit field)
Interpretation of C basic syntax: summarize some commonly used but easily confused functions (i++ and ++i) in the program (bit field)
2022-07-27 16:40:00 【CDamogu】



1> i++ And ++i
i++ and ++i yes C Language operators ,i++ It means increasing suffix ,++i Prefix increment means .
i++It means increasing suffix ,i++ Is to do the expression operation first , And then we're going to do the self-increment . hold i++ Split the operation process of , Equivalent to i=i+1 You can see that the calculation results are consistent .x = i ++; // First, let x become i Value 1, let i Add 1++iPrefix increment means ,++i Is to perform self increasing or self decreasing operation first , And then we do the expression operation . The result of the operation shows that , Only i From the value of ,++i and i++ The final i The value is the same , All are i Since then 1.x = ++i; // First, let i Add 1, let x become i Value 1
2> Understanding of bit field (int a:4);
The following procedure is in linux The system has been compiled
1 /*--------------------------------------------------------------------- 2 * Function: bit area 3 * Author: CDamogu 4 * Date: 2022/7/12 5 * Description: How to unstandard bit area,for example: int a:4; 6 * Opeartion System: Linux 7 ----------------------------------------------------------------------*/
8 #include <stdio.h>
9
10
11 struct bs
12 {
13 unsigned int a:4;
14 unsigned int b:4;
15 unsigned int c:2;
16 unsigned int d:6;
17 }structa;
18
19
20 void main()
21 {
22 structa.a=15;
23 structa.b=8;
24 structa.c=2;
25 structa.d=23;
26
27 printf("a is %d\n",structa.a);
28 printf("b is %d\n",structa.b);
29 printf("c is %d\n",structa.c);
30 printf("d is %d\n",structa.d);
31 printf("structa is %X(H)\n",structa);
32 printf("5E8F To Bin is: 0101 1110 1000 1111\n");
33 printf("5E8F To Bin is: 010111 10 1000 1111\n");
34 printf("5E8F To Bin is: 23 2 8 15 \n");
35
36 }
The results are as follows :
[[email protected] tes1]# ./a.out
a is 15
b is 8
c is 2
d is 23
structa is 5E8F(H)
5E8F To Bin is: 0101 1110 1000 1111
5E8F To Bin is: 010111 10 1000 1111
5E8F To Bin is: 23 2 8 15
[[email protected] tes1]#
5E8F This value is after I execute , Then the following program adds three lines of parsing , In order to facilitate the understanding of the defined order and the high and low positions stored in the space after execution
Prototype of bit field function
struct name { type var_name : n; };- In structure name Summary , Member variables var_name The occupied space is n position .
- n As a positive integer , Its value must be less than type Number of digits occupied by type .
- Such as type If it is int, Occupy 4 byte 32 position , that n Must be 1~31 Integer between .
- For members of bit field type , If the actual value exceeds n The range that bits can express , Then the excess will be cut off , Save only the low value .
- Such as
int var:4, Itself only 4 Bit space , If the assignment isvar = 20, because 20 The binary value of is 10100, Actually five , At this time var What is actually assigned is the lower four digits ,0100, namely 4.
- Such as
- because C The address in the language is calculated for bytes , Therefore, member variables of bit field type do not support address fetching
- That is, for variables a, If there is a bit field member variable var, that
&a.varIt's illegal. , Compilation error .
- That is, for variables a, If there is a bit field member variable var, that
A bit field must be stored in the same byte , Can't span two bytes .
- If there is not enough space left for one byte to store another bit field , The bit field should be stored from the next unit . You can also intentionally start a bit field from the next unit .
struct bs { unsigned a:4 unsigned :0 /* airspace */ unsigned b:4 /* Store from next unit */ unsigned c:4 } // In this bit field definition ,a The first byte 4 position , after 4 Place filling 0 No use ,b Start with the second byte , Occupy 4 position ,c Occupy 4 position .A bit domain can be a bit free domain name , At this time, it is only used for filling or adjusting the position . Nameless bit fields cannot be used . for example :
struct k { int a:1 int :2 /* The 2 Bit cannot be used */ int b:3 int c:2 }; // As can be seen from the above analysis , Bit fields are essentially structural types , But its members are allocated in binary .
边栏推荐
- What is ti's calculation for successively canceling the agency rights of anfuli / Wenye / Shiping?
- const小结
- Crawl common English names
- Const summary
- ADAMS中转动整个模型
- [paper reading] a CNN transformer hybrid approach for cropclassification using multitemporalmultisensor images
- Configuration and application of gurobi in pycharm
- OpenCV(四)——图像特征与目标检测
- TP5 -- query field contains a certain --find of search criteria_ IN_ SET
- 使用百度飞桨EasyDL实现电商UGC图片自动分类
猜你喜欢

CDQ divide and conquer and whole dichotomy learning notes

DRF learning notes (V): viewset

SolidWorks simulation curve attribute setting

Quadratic programming based on osqp

Collection! 0 basic open source data visualization platform flyfish large screen development guide

Log management

my_ Ls summary

training on multiple GPUs pytorch

Is low code the future of development? On low code platform

【论文阅读】A CNN-Transformer Hybrid Approach for CropClassification Using MultitemporalMultisensor Images
随机推荐
(二)动态卷积之Dynamic Convolution
论文缩小
OpenCV(三)——图像分割
OpenCV(一)——图像基础知识
Solve the problem that ${pagecontext.request.contextpath} is invalid
ADAMS中转动整个模型
Script file ‘D:\programs\anaconda3\Scripts\pip-script. py‘ is not present.
Casadi -- detailed explanation of data types and introduction to basic operations
Log management
Configuration and application of gurobi in pycharm
Cron expression use
OpenCV(四)——图像特征与目标检测
Json数据的格式使用
string数字类型转换为千分位
2021 national vocational college skills competition (secondary vocational group) network security competition questions (9) ideas
Duplicate numbers in array
201403-1
2021-06-02
Find active SQL connections in SQL Server
插入word中的图片保持高dpi方法