-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathc语言.txt
45 lines (40 loc) · 1.85 KB
/
c语言.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
内存空间访问:
指针的核心:
1.分配多大指针空间
32位系统(32位):
2^10b = 1K
2^20 = 1M
2^30 = 1G
2^32 = 4G
2.地址指向资源的读取解析方法
abc@DESKTOP-SV1JI86:~/clan$ cat test.c #include <stdio.h>
int main() {
int a = 0xA1B2C3D4;
int *p1;
char *p2;
p1 = &a;
//指针值为地址的最小值 不管大端小端存储;
p2 = &a;
printf("the p1 sizeof is %lu\n",sizeof(p1));
printf("the p2 sizeof is %lu\n",sizeof(p2));
printf("the p1 value is %x\n",*p1);
printf("the p2 value is %x\n",*p2);
}
abc@DESKTOP-SV1JI86:~/clan$ gcc test.c
test.c: In function ‘main’: test.c:9:6: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] p2 = &a; ^ abc@DESKTOP-SV1JI86:~/clan$ ./a.out
the p1 sizeof is 8
the p2 sizeof is 8
the p1 value is a1b2c3d4
the p2 value is ffffffd4
指针指向的内存空间一定要保证合法性
指针修饰符:
const:
const char *p = char const *p; ==>>字符串
char * const p = char *p const; ==>>硬件资源
const char * const p
volatile 不优化
volatile char *p;
一般说来,volatile关键字用在如下的几个地方。
(1)中断服务程序中修改的供其他程序检测的变量需要加volatile。
(2)多任务环境下各任务间共享的标志应该加volatile。
(3)存储器映射的硬件寄存器通常也要加volatile说明,因为每次对它的读写都可能有不同意义。