找传奇、传世资源到传世资源站!

[Understanding.and.Using.C.Pointers(2013.5...

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardTable 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

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复