Table of ContentsPreface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix1. Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Pointers and Memory 2Why You Should Become Proficient with Pointers 3Declaring Pointers 5How to Read a Declaration 7Address of Operator 8Displaying Pointer Values 9Dereferencing a Pointer Using the Indirection Operator 11Pointers to Functions 11The Concept of Null 11Pointer Size and Types 15Memory Models 16Predefined Pointer-Related Types 16Pointer Operators 20Pointer Arithmetic 20Comparing Pointers 25Common Uses of Pointers 25Multiple Levels of Indirection 25Constants and Pointers 27Summary 322. Dynamic Memory Management in C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33Dynamic Memory Allocation 34Memory Leaks 37Dynamic Memory Allocation Functions 39Using the malloc Function 39Using the calloc Function 43iiiUsing the realloc Function 44The alloca Function and Variable Length Arrays 46Deallocating Memory Using the free Function 47Assigning NULL to a Freed Pointer 48Double Free 48The Heap and System Memory 50Freeing Memory upon Program Termination 50Dangling Pointers 51Dangling Pointer Examples 51Dealing with Dangling Pointers 53Debug Version Support for Detecting Memory Leaks 54Dynamic Memory Allocation Technologies 54Garbage Collection in C 55Resource Acquisition Is Initialization 55Using Exception Handlers 56Summary 563. Pointers and Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57Program Stack and Heap 58Program Stack 58Organization of a Stack Frame 59Passing and Returning by Pointer 61Passing Data Using a Pointer 62Passing Data by Value 62Passing a Pointer to a Constant 63Returning a Pointer 64Pointers to Local Data 66Passing Null Pointers 67Passing a Pointer to a Pointer 68Function Pointers 71Declaring Function Pointers 72Using a Function Pointer 73Passing Function Pointers 74Returning Function Pointers 75Using an Array of Function Pointers 76Comparing Function Pointers 77Casting Function Pointers 77Summary 784. Pointers and Arrays. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79Quick Review of Arrays 80One-Dimensional Arrays 80iv | Table of ContentsTwo-Dimensional Arrays 81Multidimensional Arrays 82Pointer Notation and Arrays 83Differences Between Arrays and Pointers 85Using malloc to Create a One-Dimensional Array 86Using the realloc Function to Resize an Array 87Passing a One-Dimensional Array 90Using Array Notation 90Using Pointer Notation 91Using a One-Dimensional Array of Pointers 92Pointers and Multidimensional Arrays 94Passing a Multidimensional Array 96Dynamically Allocating a Two-Dimensional Array 99Allocating Potentially Noncontiguous Memory 100Allocating Contiguous Memory 100Jagged Arrays and Pointers 102Summary 1055. Pointers and Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107String Fundamentals 107String Declaration 108The String Literal Pool 109String Initialization 110Standard String Operations 114Comparing Strings 115Copying Strings 116Concatenating Strings 118Passing Strings 121Passing a Simple String 121Passing a Pointer to a Constant char 123Passing a String to Be Initialized 123Passing Arguments to an Application 125Returning Strings 126Returning the Address of a Literal 126Returning the Address of Dynamically Allocated Memory 128Function Pointers and Strings 130Summary 1326. Pointers and Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Introduction 133How Memory Is Allocated for a Structure 135Structure Deallocation Issues 136Table of Contents | vAvoiding malloc/free Overhead 139Using Pointers to Support Data Structures 141Single-Linked List 142Using Pointers to Support a Queue 149Using Pointers to Support a Stack 152Using Pointers to Support a Tree 154Summary 1587. Security Issues and the Improper Use of Pointers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159Pointer Declaration and Initialization 160Improper Pointer Declaration 160Failure to Initialize a Pointer Before It Is Used 161Dealing with Uninitialized Pointers 162Pointer Usage Issues 162Test for NULL 163Misuse of the Dereference Operator 163Dangling Pointers 164Accessing Memory Outside the Bounds of an Array 164Calculating the Array Size Incorrectly 165Misusing the sizeof Operator 166Always Match Pointer Types 166Bounded Pointers 167String Security Issues 168Pointer Arithmetic and Structures 169Function Pointer Issues 170Memory Deallocation Issues 172Double Free 172Clearing Sensitive Data 173Using Static Analysis Tools 173Summary 1748. Odds and Ends. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175Casting Pointers 176Accessing a Special Purpose Address 177Accessing a Port 178Accessing Memory using DMA 179Determining the Endianness of a Machine 180Aliasing, Strict Aliasing, and the restrict Keyword 180Using a Union to Represent a Value in Multiple Ways 182Strict Aliasing 183Using the restrict Keyword 184Threads and Pointers 185vi | Table of ContentsSharing Pointers Between Threads 186Using Function Pointers to Support Callbacks 188Object-Oriented Techniques 190Creating and Using an Opaque Pointer 190Polymorphism in C 194Summary 199Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
下载[Understanding.and.Using.C.Pointers(2013.5)].Richard.Reese.文字版用户还喜欢
- 18480 文章数
- 500万+ 热度
作者专栏
编辑推荐
- 淡抹u2引擎,修复内容较多,物有所值
- 界域传说·经典巨作=传世单机(一键安装)
- 丸子版本(175个传世版本大集合)
- GS版本:神话公益服务端+客户端
- 图片放大工具(放大图片不模糊)
- 剪映无限制VIP版
- 传奇世界客户端下载器,史上最全传世客户端
- 传世GS20220920商业引擎注册+登录配置器 解压密码是1
- U2官方排行榜游戏网关 支持元神,支持传家宝
- GS开战传世客户端+服务端
- (淡漠夕阳)u2引擎合区工具
- 传世GS引擎消除“你的游戏客户端版本号过旧,请及时更新”提示
- 传世一机多区双线路配置器--免密码版本
- 传世凤凰登陆器劫持修复软件
- SQLite3 for Navicat
- 传奇世界npc对话框编辑工具
- 传世GS落霞铭文服务器端
- gs_20210409引擎包+注册机(无限制)
- 传奇世界NPC对话封包查看器[支持时长版和极速版]
- 彩虹引擎传世脚本编辑工具1.7版来了,支持函数脚本翻译
评论