warning C4047: 'initializing' : 'char *' differs in levels of indirection from 'const int '

以下来自MSDN

编译器警告(等级 1)C4047

错误消息

“operator”:“identifier1”与“identifier2”的间接寻址级别不同

指针可指向变量(一级间接寻址),指向另一个指向变量的指针(二级间接寻址)等。

示例

下面的示例生成 C4047:

// C4047.c
// compile with: /W1

int main() {
   char **p = 0;   // two levels of indirection
   char *q = 0;   // one level of indirection

   char *p2 = 0;   // one level of indirection
   char *q2 = 0;   // one level of indirection

   p = q;   // C4047
   p2 = q2;
}

下面的示例生成 C4047:

// C4047b.c
// compile with: /W1
#include 

int main() {
   int i;
   FILE *myFile = NULL;
   errno_t  err = 0;
   char file_name[256];
   char *cs = 0;

   err = fopen_s(&myFile, "C4047.txt", "r");
   if ((err != 0) || (myFile)) {
      printf_s("fopen_s failed!/n");
      exit(-1);
    }
   i = fgets(file_name, 256, myFile);   // C4047
   cs = fgets(file_name, 256, myFile);   // OK

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
目录 需要英语好一点的人看 Contents 1 Introduction 1 What You Will Learn from This Book 2 7 19 23 27 How This Book Is Organized Support 5 Acknowledgments 5 Preface to the Fourth Edition 2 Programming in Objective-C 3 6 7 Compiling and Running Programs Using Xcode 8 Using Terminal Explanation of Your First Program Displaying the Values of Variables Summary 25 Exercises 25 3 Classes, Objects, and Methods 17 What Is an Object, Anyway? 27 Instances and Methods 28 An Objective-C Class for Working with Fractions 30 The @interface Section 33 Choosing Names 34 Class and Instance Methods 35 The @implementation Section 37 The program Section 39 Accessing Instance Variables and Data Encapsulation 45 Summary 49 Exercises 49 4 Data Types and Expressions 51 Data Types and Constants 51 Type int 51 Type float 52 Type char 52viii Contents Qualifiers: long, long long, short, unsigned, and signed 53 Type id 54 Arithmetic Expressions 55 Operator Precedence 55 Integer Arithmetic and the Unary Minus Operator 58 The Modulus Operator 60 Integer and Floating-Point Conversions 61 The Type Cast Operator 63 Assignment Operators 64 A Calculator Class 65 Exercises 67 5 Program Looping 71 The for Statement 72 Keyboard Input 79 Nested for Loops 81 for Loop Variants 83 The while Statement 84 The do Statement 88 The break Statement 90 The continue Statement 90 Summary 91 Exercises 91 6 Making Decisions 93 The if Statement 93 The if-else Construct 98 Compound Relational Tests 100 Nested if Statements 103 The else if Construct 105 The switch Statement 114 Boolean Variables 117 The Conditional Operator 122 Exercises 124 7 More on Classes 127 Separate Interface and Implementation Files 127 Synthesized Accessor Methods 132 Accessing Properties Using the Dot Operator 134 Multiple Arguments to Methods 135 Methods Without Argument Names 137 Operations on Fractions 137 Local Variables 140 Method Arguments 141 The static Keyword 141 The self Keyword 145 Allocating and Returning Objects from Methods 146 Extending Class Definitions and the Interface File 148 Exercises 148 8 Inheritance 151 It All Begins at the Root 151 Finding the Right Method 155 Extension Through Inheritance: Adding New Methods 156 A Point Class and Object Allocation 160 The @class Directive 161 Classes Owning Their Objects 165 Overriding Methods 169 Which Method Is Selected? 171 Abstract Classes 173 Exercises 174 9 Polymorphism, Dynamic Typing, and Dynamic Binding 177 Polymorphism: Same Name, Different Class 177 Dynamic Binding and the id Type 180 Compile Time Versus Runtime Checking 182 The id Data Type and Static Typing 183 Argument and Return Types with Dynamic Typing 184 Asking Questions About Classes 185 Exception Handling Using @try 189 Exercises 192 Contents ix x Contents 10 More on Variables and Data Types 195 Initializing Objects 195 Scope Revisited 198 Directives for Controlling Instance Variable Scope 198 More on Properties, Synthesized Accessors, and Instance Variables 200 Global Variables 200 Static Variables 202 Enumerated Data Types 205 208 The typedef Statement Data Type Conversions 209 Conversion Rules 210 Bit Operators 211 The Bitwise AND Operator 212 The Bitwise Inclusive-OR Operator 213 The Bitwise Exclusive-OR Operator 214 The Ones Complement Operator The Left Shift Operator 216 The Right Shift Operator 216 Exercises 217 11 Categories and Protocols 219 Categories 219 Class Extensions 224 214 Some Notes About Categories 225 Protocols and Delegation 226 Delegation 229 Informal Protocols 229 Composite Objects 230 Exercises 231 12 The Preprocessor 233 The #define Statement 233 More Advanced Types of Definitions 235 The #import Statement 240 Conditional Compilation 241 The #ifdef, #endif, #else 241 The #if and #elif Preprocessor Statements 243 The #undef Statement 244 Exercises 245 13 Underlying C Language Features 247 Arrays 248 Initializing Array Elements 250 Character Arrays 251 Multidimensional Arrays 252 Functions 254 Arguments and Local Variables 255 Returning Function Results 257 Functions, Methods, and Arrays 261 Blocks 262 Structures 266 Initializing Structures 269 Structures Within Structures 270 Additional Details About Structures 272 Don’t Forget About Object-Oriented Programming! 273 Pointers 273 Pointers and Structures 277 Pointers, Methods, and Functions 279 Pointers and Arrays 280 Constant Character Strings and Pointers 286 Operations on Pointers 290 Pointers and Memory Addresses 292 They’re Not Objects! 293 Miscellaneous Language Features 293 Compound Literals 293 The goto Statement 294 The null Statement 294 The Comma Operator 294 The sizeof Operator 295 Command-Line Arguments 296 How Things Work 298 Fact #1: Instance Variables Are Stored in Structures 298 Fact #2: An Object Variable Is Really a Pointer 299 Fact #3: Methods Are Functions, and Message Expressions Are Function Calls 299 Fact #4: The id Type Is a Generic Pointer Type 299 Exercises 300 Contents xi xii Contents 14 Introduction to the Foundation Framework 303 Foundation Documentation 303 15 Numbers, Strings, and Collections 307 Number Objects 307 String Objects 312 More on the NSLog Function 312 The description Method 313 Mutable Versus Immutable Objects 314 Mutable Strings 320 Array Objects 327 Making an Address Book 330 Sorting Arrays 347 Dictionary Objects 354 Enumerating a Dictionary 355 Set Objects 358 NSIndexSet 362 Exercises 365 16 Working with Files 369 Managing Files and Directories: NSFileManager 370 Working with the NSData Class 375 Working with Directories 376 Enumerating the Contents of a Directory 379 Working with Paths: NSPathUtilities.h 381 Common Methods for Working with Paths 383 Copying Files and Using the NSProcessInfo Class 386 Basic File Operations: NSFileHandle 390 The NSURL Class 395 The NSBundle Class 396 Exercises 397 17 Memory Management and Automatic Reference Counting 399 Automatic Garbage Collection 401 Manual Reference Counting 402 Object References and the Autorelease Pool 403 The Event Loop and Memory Allocation 405 Summary of Manual Memory Management Rules 407 Automatic Reference Counting (ARC) 408 Strong Variables 408 Weak Variables 409 @autoreleasepool Blocks 410 Method Names and Non-ARC Compiled Code 411 18 Copying Objects 413 The copy and mutableCopy Methods 413 Shallow Versus Deep Copying 416 Implementing the <NSCopying> Protocol 418 Copying Objects in Setter and Getter Methods Exercises 423 19 Archiving 425 Archiving with XML Property Lists 425 Archiving with NSKeyedArchiver 427 Writing Encoding and Decoding Methods 429 Using NSData to Create Custom Archives 436 Using the Archiver to Copy Objects 439 Exercises 441 421 20 Introduction to Cocoa and Cocoa Touch Framework Layers 443 Cocoa Touch 444 21 Writing iOS Applications 447 The iOS SDK 447 Your First iPhone Application 447 Creating a New iPhone Application Project Entering Your Code 452 Designing the Interface 455 443 449 An iPhone Fraction Calculator 461 Starting the New Fraction_Calculator Project 462 Defining the View Controller 464 Contents xiii xiv Contents The Fraction Class 469 A Calculator Class That Deals with Fractions 473 Designing the UI 474 Summary 475 Exercises 476 A Glossary 479 B Address Book Example Source Code 487 Index 493

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值