{"id":15049053,"url":"https://github.com/ascendho/conquer-c-pointer","last_synced_at":"2026-02-12T20:03:27.454Z","repository":{"id":231633944,"uuid":"781344932","full_name":"ascendho/Conquer-C-Pointer","owner":"ascendho","description":"《征服C指针(第2版)》 前桥和弥/著 朱文佳/译","archived":false,"fork":false,"pushed_at":"2024-04-11T02:09:06.000Z","size":354,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-10T05:25:25.247Z","etag":null,"topics":["c-programming-language","pointer"],"latest_commit_sha":null,"homepage":"https://www.ituring.com.cn/book/2638","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ascendho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-04-03T07:53:19.000Z","updated_at":"2024-04-05T01:35:19.000Z","dependencies_parsed_at":"2024-04-05T02:41:08.642Z","dependency_job_id":"260a6deb-bbe8-42e4-b37a-c0d86f8b7ec4","html_url":"https://github.com/ascendho/Conquer-C-Pointer","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"dfaa5af42a823574f8ec2e4a8824b4d0a23a22c6"},"previous_names":["ascendho/conquer-c-pointer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ascendho/Conquer-C-Pointer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascendho%2FConquer-C-Pointer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascendho%2FConquer-C-Pointer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascendho%2FConquer-C-Pointer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascendho%2FConquer-C-Pointer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ascendho","download_url":"https://codeload.github.com/ascendho/Conquer-C-Pointer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ascendho%2FConquer-C-Pointer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29379684,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-12T19:05:20.189Z","status":"ssl_error","status_checked_at":"2026-02-12T19:01:44.216Z","response_time":55,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-programming-language","pointer"],"created_at":"2024-09-24T21:17:48.528Z","updated_at":"2026-02-12T20:03:27.416Z","avatar_url":"https://github.com/ascendho.png","language":"C","readme":"## 第一章\n\n- 为什么不能进行`str==\"abc\"`这样的比较？\n\n字符串其实就是char类型的数组，也就是说它不是标量，所以在C语言中不能使用\"==\"一下子对数组里的所有元素进行比较\n\n\n\n- 所谓指针，不就是地址吗，无论是指向int的指针还是指向double的指针，有必要区分吗？\n\n思考一下这段代码：\n\n```c\nvoid *hoge_p = \u0026hoge;\nprintf(\"%d\\n\", *hoge_p);\n```\n\n当然会报错，因为你没有告知该起始地址上保存的是什么类型的数据，不知道应该在哪里停止读取。不同的数据类型的长度一般不同，如int可能占据4个字节，而double占据8个字节。\n\n\n\n- 无论有没有[]，在表达式中，数组名会被解读成指向数组**初始**元素的**指针**。\n\n例如array[i]会被解读成*(array+i)，array是起始元素地址。\n\n例外情况：见第三章笔记。\n\n\n\n- 为什么存在**指针运算**这种奇怪的功能？\n\n原因之一是受到了其祖先B语言的影响。\n\nB是没有类型的语言，可以使用的类型只有word类型(总之就是整数类型)，指针也被当成整数处理的，而B语言的地址也是以word为单位的，所以对指针(单纯表示地址的整数)加1，指针就会自动指向数组的下一个元素。为了继承这一点，C语言里引入了“对指针加1，则指针前进该指针所指向的类型的长度”这一规则。\n\n另一个原因是，以前使用指针运算能写出更高效的程序，但现在随着编译器的不断优化，不论是使用数组还是指针运算，效率上都不会有什么明显的差异。大部分情况下，生成的机器码是完全相同的。\n\n------\n\n\n\n## 第二章\n\n- 在朴素的实现方式中，可变参数**实参**的值是**从后往前**按顺序压栈的。\n\n比较典型的`printf()`函数，例如`printf(\"%d, %s\\n\",100,str);`此时重要的是不论压进多少个参数，总能找到第一个参数的地址。所以应该先压进`str`和`100`，然后才是指向`\"%d, %s\\n\"`的指针，再加上恢复信息、返回地址、局部变量等等。此时只要能够获取第一个参数，就能够通过解析字符串`\"%d, %s\\n\"`知晓后面还有多少个什么样的参数，然后可以按顺序将它们依次取出。\n\n\n\n- `malloc()`是系统调用吗？\n\n先说说系统调用，系统调用是指要求操作系统帮我们去执行某些操作的特别的函数集。\n\n在UNIX中，`printf()`最终会调用称为`write()`的系统调用。不只是`printf()`，`putchar()`和`puts()`最终调用的也是`write()`。\n\n回到`malloc()`函数，实际上，它是标准库函数，不是系统调用。\n\n\n\n- `sizeof(struct)`的大小**不是**简单地将结构体各个成员字节数目相加的结果。\n\n根据硬件(CPU)的不同，对不同的数据类型能够配置的地址是有限制的。就算能够配置，某些CPU的效率也会变差。在这种情况下，编译器会进行适当的边界调整(对齐，**alignment**)，向结构体插入适当的填充(**padding**)。填充有时会被放在结构体的末尾。\n\n\n\n- 结构体的成员名称在运行时也是**缺失**的。\n\n对结构体成员的引用是通过距离结构体起始地址的偏移量(字节单位的距离)实现的。而并不是通过名称(如item)引用结构体成员的。因此，如果结构体的定义发生了变化，就必须将使用这个结构体的源文件全部重新编译一遍。\n\n------\n\n## 第三章\n\n- 针对如下代码，\n\n```c\nint array[3];\nint (*array_p)[3];\n```\n\n`array_p=\u0026array`和`array_p=array`(后者等价于array_p=\u0026array[0])是不同的，后者编译器会发出警报。一个是指向int的数组(元素个数为3)的指针，一个是执行int的指针，两者是完全不同的类型。\n\n自加1后，前者指针前进12字节(假设int类型长度是4字节)，而后者只前进4字节，指向下一个元素。\n\n\n\n- 传递二维数组作为函数参数时，`void func(int hoge[3][2])`和`void func(int hoge[][2])`其实都是`void func(int (*hoge)[2])`的语法糖，意思完全相同。\n\n\n\n- “在表达式中，数组会被解读为指针的例外情况”：\n\n1. 当作为sizeof运算符的操作数时。\n2. 当作为\u0026运算符的操作数时。如`int (*array_p)[3]=\u0026array;`。\n3. 初始化数组时的字符串字面量。如`char str[10]=\"ascendho;\"`，由于字符串字面量是”char的数组“，所以在表达式中一般会解读为”指向char的指针“，但关于初始化char的数组时的字符串字面量，编译器通常会将其特别解释为花括号内字符分段书写的初始化列表的省略形式。请注意它与初始化char的指针时的字符串字面量的区别。\n\n------\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fascendho%2Fconquer-c-pointer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fascendho%2Fconquer-c-pointer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fascendho%2Fconquer-c-pointer/lists"}