Preface
Like any kind of human language, C provides a method of expression concept. If this method is successful, then this medium will be more powerful than other methods when the size and complexity of the problem are gradually large, and the use is also simpler, more flexible.
C cannot be seen as a simple collection of some features, some of which are not meaningful if used alone. They should be considered as a whole when designing and encoding. To really understand this, you need to understand some questions in C language, as well as general issues that will appear in the program. This book discusses some problems encountered in programming, as well as the reason why they become a problem, and then explain C to solve these problems. Therefore, the characteristics discussed in each chapter are the features of a set of organic customs that will be used in this language to solve a particular type of problem. I hope to gradually instill C concept into a person who is used to a C language to become your "native language".
And in the whole book, I have tried to help you build such a model in the brain so that you can understand all the secrets behind this language, so when you encounter a little doubt, you can use this model to guide yourself to find the answer. . I will try to communicate my mind to you for C , this understanding allows me to "think with C ".
What is the second edition of What's New In The Second Edition?
Relative to the first edition, this book is completely overwritten once, it fully follows the final C standard (this standard is somewhat different from the previous C version), and also reflects that I have written this book. Some things you have learned sincerely. All the words in the first edition have been re-examined and revised, and some old examples have been removed, some examples have modified, and some new examples have also joined many new exercises. The major adjustment of the material is based on the following two reasons, one is to help people understand and use some more features, but also because of how people have learned C this year. I have some new. Experience. This version has added a new chapter, and concisely introduces the basic concepts of the C language and the basic characteristics of C , which makes those who do not have a C language background can also deal with other contents of this book.
So for this question: "What is the difference between the second version of this book", the simplest answer is to rewrite the content that does not meet the new standard in the first edition, which is not clear in the original material. Some points have been clearly reflected in the new version.
What is the second volume of this book (What's in volume 2 of this book)
A number of important libraries in C standards, such as String, containers, and algorithms in standard C libraries, etc., and the templates are more complicated. These and some other advanced themes, such as multiple inheritance, abnormal processing, design patterns, and how to establish and debug stabilize systems are classified into the second volume of this book.
How to get the English version of the second volume (How to get Volume 2)
The second volume of this book can also download from my website www.bruceeckel.com. From there, you can also see the scheduled date for the second volume. There is also the source code of these two books on the website and some other information.
Background knowledge (prerequisites)
In the first edition of this book, I did a hypothesis that readers have already understood the basic knowledge of the C language required by this book. My initial focus on how I clarified that I think the most difficult place: C language itself. In this version, I joined a chapter used to make a concise introduction to C, but I still assume that you have certain programming experience. In addition, when reading a novel, you can often guess some new words in the context. In other parts of this book, you can learn something about C language. Learn C (Learning C )
Many readers may be the same as I started to learn C , and it is very serious and fanatical. And I may be worse, because I have been doing hardware-level embedded programming, where C language is usually seen as senior languages, and the efficiency is not satisfactory when working on binary bits. Later I found that I am not even a good C programmer, for data structures, malloc (), free (), setjmp (), longjmp (), and other "complex" concepts is ignorant, when talking to these things It is always very shy to escape, not trying to master these new things.
When I started learning C , the only picture-like book is "The C Programming Language" that Bjarne Stroustrup claims to be "Expert Guide", so I need to figure out some basic concepts. This has achieved my first book: "Using C ", it is basically my own experience. The idea at the time was to bring readers to the world of C and C . The two versions of this book ("Usinger C " and "C Inside & Out" have received enthusiastic responses from readers.
While "USING C " this book, I started to teach this language. Professor C (later also teaching Java) became my profession. Since 1989, in the teaching activities around the world, they often find the audience to sleep, it is stunned or confused. When I conducted some groups in indoor training, some things were discovered in the process of practicing. Although the students will have a smile, but in fact they have not made very clear about many problems. By creating and hosting the Multi-year experience of C and Java forums in the Software Development Seminar, I finally discovered the problem, that is, I am always trying to instill too many themes to students as soon as possible. Finally, due to the different levels in the students, this professor I use will eventually exit in some people. Maybe a little excessive, but because I am also one of the boycots of traditional teaching methods (I believe that this kind of resistance to most people is because this method is tired), I hope that everyone can make eachone can fly.
For a while, I created a series of different fast teaching programs, continuously learned from experiments and feedback this iterative process (often used in C programming). Finally, according to all these experiences accumulated from the teaching, I have developed a courseway. It divides the entire learning process into a sub-process for discrete, easy to digest and absorbed, and teaching form is a regular seminar (this is an ideal way to learn), and some exercises will be conducted after each seminar. You can get information released in my open seminar from www.bruceeckel.com.
The first version of this book is written in two years of teaching, and the examples in this book are in a variety of different forms at different seminars. Feedback received at each seminar helps me to modify and adjust the materials in the book until I think it has been truly suitable as a textbook. But it is not a print of the seminar, and I have carefully selected and reroute the material, so that you can transition from one topic to another. More importantly, this book is also designed for the loneliness student who struggles for new programming languages, and self-learners can take this into the world of C . Goals
The purpose of this book is:
1. Gradually to display the material, so that the reader can easily absorb each concept, and then carry out the following learning.
Use simple short examples as much as possible. In this way, it is usually not used in the "Real World". Maybe the scope of the real problem that can be solved in this language will leave a deep impression on the reader, but I found that for beginners, when they Many happiness that can be obtained when every detail in the example is. At the same time, the number of sample code for teaching is also subject to some restrictions. For this reason, it is often criticized that I always use some "Pediatric Examples", I acknowledge this because it can be more teaching. Rationally arrange the sequence of teaching to avoid the characteristics that have not been tailored in the previous chapter. Of course, this may not be possible, and this feature will be a brief description. I only teach the readers I think about understanding this language. It is not to show all the things I know. I believe that "information is important level", there are some 95% of the programmers who will not be used, and they will only confuse them, and they think that this language is so complicated. For example, just like the operator priority in the C language, if you can remember all operator priorities (I can't do it), you can write a very delicate code. But in this case, the code readers and maintaines, and even you will be confused by this intrinsic priority relationship. Therefore, it is best to do any priority. When there is such a little unclear, it is not hesitant to use parentheses. You can also treat some things in C . I think these things are more important to the compiler, not the programmer. The content of each part is more concentrated, which makes the speaker's time, and the interval between exercises is relatively reasonable. This not only allows students to maintain a positive attitude in this series of learning, but also give readers more accomplishment. The reader has made a solid foundation so that they truly understand these contents, so that higher levels of learning (including learning for the second volume). I try not to use any specific version of C , because for the learning language, I think the language is important than a particular implementation. And each version of C comes with a detailed description of it has been made in the documentation included.
Chapter introduction (Chapter)
C is a new feature based on existing grammar, so it is not a purebred object-oriented programming language. Many people have gone some detours in the process of learning this language, which allows us to gradually realize some of the processes experienced when learning C languages. This process is very natural for a brain that has been smoked for many years facing process programming. I tried to explore and follow this process, and accelerated this process by propose and answer some questions. Some of these issues were what I have encountered. Some are the students from the language of our professor.
When designing this course, I always maintain an idea: keep the C learning process remains natural and smooth. The feedback of the audience made me realize which parts are more difficult and need more elaboration. I have a strong wish in some parts, I want to tell a lot of features, I will slowly realize that if this is, all of these features must be explained clearly, and the students will put multiple different characteristics. Mutual involvement, making it paste. Later, I spent a lot of effort to adjust, thus only introducing as few features as possible, ideal, one chapter contains only one main concept. My goal is that each chapter only introduces a concept, or few related concepts, not involving other features. In this way, on the basis of existing knowledge, the pieces of pieces can be integrated, and then proceed to proceed. In order to do this, I preserved some of the characteristics of some C language in the appropriate place. In this way, it is not available before introducing C characteristics to confuse the reader. In this way, your C trip will be very smooth, gradually absorbing these new features.
Below is a brief introduction to each chapter in this book:
Chapter 1: Introduction To Objects. When the project has become too large and more complicated, it has caused the "Software Crisis" when it is difficult to maintain, and the programmer said: "We are difficult to complete this project, even if we have completed, it is too expensive. ! "This crisis has caused a variety of reactions. It is discussed in this chapter to use the object-oriented programming method (OOP) to eliminate the software crisis. This chapter describes some basic concepts and features of object-oriented programming, and also introduces the analysis and design process. In addition, it will also be described with the benefits of using this language and how to transfer some suggestions from the C world.
Chapter 2: Constructor and uses objects (MAKING AND Using Objects). This chapter describes the process of establishing a program with a library and a compiler. The first C program example in this book is introduced here, and how the program is constructed and compiled. Then introduced some libraries for some basic objects in the standard C library. By studying this chapter, you will understand the huge significance to use the existing object library for writing C programs.
CHAPTER 3: C (THE C IN C ) in CHAPTER 3: C . This chapter has made a concise intention of the characteristics used in C , and also introduced some basic features that exist in C . It also introduces a tool "Make" that is generally used in software development. This chapter assumes that you have a better process language (such as Pascal, C even Basic, as long as you write enough code, especially the function) programming. If you think this chapter is still a bit difficult, you can first look at "Thinking In C" book (you can download from www.bruceeckel.com).
Chapter 4: Data Abstract. Most of C is all about creating new data types. This not only can better organize code, but also the cornerstone of other powerful characteristics in object-oriented programming. You will find that this is very simple, just put the function within the structure, you will see the details, and you will recognize what code it can bring you. Finally, I will learn how to organize the code to the header file and implement files.
Chapter 5: Hidden Hidden. You can make certain functions and data in a new type of users are invisible to users of this type, as long as they declare them as private. This means that you can separate the implementation part from the interface you can see, so that you can easily modify the implementation portion and not affect the code of the customer. Here, keyword class is introduced to describe new data types. Here, the meaning of "object" is no longer so mysterious (it is just a special variable). Chapter 6: Initialization and Cleanup. The most common mistake in C is often derived from the variables that are not initialized. The constructor in C can ensure that the variable of the new data type can always be correctly initialized. If your object also needs some kind of clear operation, you can also use C destructor to ensure.
Chapter 7: Function overload and default parameters (Function overloading and default arguments). C can be used to help you build large and complicated projects. When this time, the function name repetition in multiple libraries can occur, even in a library may also use the same name to different significance. C uses function overloading to solve this problem, as long as the function's parameter list is different, then two functions can use the same name. The default parameter automatically provides default values for certain parameters, so that the same function can be called in different ways.
Chapter 8: Constants. This chapter tells the keyword const and volatile, which have some additional meaning in C , especially when used for class. You will learn what the meaning of when Const is applied to a pointer definition. It also describes the differences between the internal and external use of keyword constings in the class, and also teaches you how to create compile constants in a class.
Chapter 9: Inline functions. The macro in the preprocessor is except for the additional overhead brought by the function call, but it also masks the type check of C . The inline function makes you also call the advantages of both the true function to call both. This chapter describes the internal implementation mechanism of the inline function and its usage.
Chapter 10: Name Control. Creating a name is a most basic behavior of programming. When the project is gradually large, the number of names is increased, and it may cause the name conflict. C greatly enhances the management of the name so that you can control the visibility of the name, the visibility of the name, the name of the name and the link attribute of the name (see Chapter 10, see Chapter 10). This chapter shows how to use two techniques in C to control the name. First, use keyword static to control the visibility and link attributes of the name, and also tell the special meaning of this keyword during the class. A more useful technology controlled by the name in the global range is the Namespace feature of the C , which allows you to divide the global namespace into different areas.
CHAPTER 11: Reference and Repandes and the copy-constructor. The usage of the pointer in C is basically similar to the usage in C, but the pointer is more stringent in C . C also provides another method of operating addresses: ie referenced, which allows you to operate with the address with a normal identifier. You will also learn the copy constructor that controls the implementation of the object to incorporate objects or outgoing functions in a transmission method. Finally, it will also describe a pointer to the member. Chapter 12: Operator Overloading. This feature is sometimes become "syntactic sugar), which is used by using the operator as a function call, so that the new type of usage you define becomes" sweet ". With this chapter, you can understand that in fact operator overload is only another form of function calls, you will learn how to design your operator to deal with some easily confusing parameters and return values, and know when it will operate When a member is a member, when is it as a favorite?
Chapter 13: Dynamic Object Creation. How many aircraft will be managed in an air traffic management system? How many shapes will be used in a CAD system? In this general programming problem, the object type, quantity, and survival of the program run during operation cannot be known. In this chapter, you will see how C creates an object to create an object in a heap by keyword new and delete, so elegant to solve such problems. Also learn how to override New and Delete in different ways to control memory allocation and release.
Chapter 14: Inheritance and Comparation. Data abstraction allows you to create new types from notificated, with combinations and inheritance, you can create new types with existing types. With a combination, you can use an existing type to assemble a new type, and use inheritance to create an existing type of specific version. This chapter will learn the syntax of inheritance and combination, how to redefine functions, and the importance of constructor and destructive functions during inheritance and combination.
Chapter 15: Polymorphism and Virtual Functions. If you explore it, you may get it to explore and understand the core idea of object-oriented programming for nine months. Through some small simple examples, it is easy to learn how to create a class family with inheritance, and process all kinds of objects in this class through this class's public base class. Keyword Virtual allows you to treat all objects in this family with a general method, which is that your code does not depend on specific type information. This makes your program have scalable, so that the build and maintenance of the program are more simple, and it is also economical.
Chapter 16: Introduction to Templates.
Inheritance and combination allows you to reuse the code of the object, but this does not fully meet the needs of multiplexing. The template will achieve the purpose of the code multiplex by enabling type parameters. Container class library is based on the technology of template, and the container class is a very important tool for fast and reliable development in object-oriented programming (standard C provides a very important container class). Library. This chapter has made a good foundation for you to continue to learn this topic.
Some other advanced themes are described in the second volume of this book, this book can be downloaded at www.bruceeckel.com.
Exercises
I found that practicing in the lecture is particularly helpful in students' true understanding of the concept, so some exercises have been designed after each chapter. The number of exercises in this version is much larger than the first edition.
Many practices are quite simple, can be done in the case of teachers in class or laboratory, so that students really understand what they have learned. There are some practice to have a certain difficulty, thus makes the students who have a lifeline. These exercises are generally designed to be completed in a shorter time. The purpose of practice is mainly inspected and helped you digest this knowledge, not give you a problem (you can find some problems yourself - and usually they will come Looking for you).
Exercise Solutions
A solution about exercises can be downloaded from www.bruceeckel.com, but it is necessary to charge a certain fee. (Translator Note: You may notice that all exercises in this book are not translated into Chinese. It is interested. English is a more common language, especially in the computer world. An excellent English book rushed Going to China to the translation publication, often take a few years, can't help but sigh. It has good English reading ability to help you get faster, advanced technology and thinking. So the translator wants to help you through these exercises Many understandings related English terms. Later, a book will be published in a book about the first volume and the second volume of exercises and answers).
Source Code
The source code in this book is free to use, you can download it from www.bruceeckel.com. But without permission, these code may not be used in any publication.
These codes are packaged into zip files, and after downloading, use the appropriate tool to extract. You can see the copyright statement below in the decompressed directory:
//:!: Copyright.txt
Copyright (C) 2000, Bruce Eckel
Source Code File from The Book "Thinking In C "
All Rights Reserved Except as aLOWED by the
FOLLOWING Statements: you can free above this file
For Your Own Work (Personal or Commercial),
Including Modifications and Distribution in
Executable form only. permission is granted to use
This file in classroom situations, incruding its
Use in presentation materials, as long as the book
"Thinking In C " is Cited as The Source.
Except in Classroom Situations, You Cannot Copy
And distribute this code; instead, the sole
Distribution Point Is http://www.bruceeckel.com
(And Official Mirror Sites) Where it is IS
Available for Free. You Cannot Remove this
Copyright and notice. You Cannot Distribute
Modified Versions of The Source Code in this
Package. You canNot USE this file in printed
Media WITHOUT The Express Permission of theauthor. Bruce Eckel Makes No Representation About
The suitability of this software for any purpose.
IT IS Provided "As IS" without Express or Implied
WARRANTY OF ANY KIND, INCLUDING ANY IMPLIED
Warranty of Merchantability, Fitness for a
Particular Purpose, or non-infringement. The entire
Risk as to the Quality and Performance of the
Software is with you. Bruce Eckel and the
Publisher Shall NOT BE LIABLE for ANY DAMAGES
SUFFERED by you or any third party as a result of
USING or Distributing this Software. in no Event
Will Bruce Eckel or the Publisher Be Liable for For
Any Lost Revenue, Profit, Or Data, or For Direct,
Indirect, Special, Consesequential, Incidental, OR
Punitive Damages, HoWever Caused and Regardless Of
The theory of liability, arising out of the use of
Or inability to Use Software, Even IF Bruce Eckel
And The Publisher Have Been Advised of The
Possibility of Such Damages. SHOULD THE SOFTWARE
Prove Defective, You Assume The Cost of ALL
Necessary Servicing, Repair, or Correction. IF you
Think You'Ve Found An Error, please submit the
Correction Using The Form You Will Find AT
Www.bruceeckel.com. (please use the same
Form for non-code errors found in the book.)
/ //: ~
As long as these declarations are included, you can use this book on your project and class.
Language support (Language Support)
Your compiler may not support all the features discussed in this book, especially if you don't get the latest version of the compiler. Implementation icon C such a language is a long-term task, it is impossible to expect that all features can be developed. If you try to compile the example of this book, you get a lot of error prompts, then there is no need to debug code, which is probably that your compiler does not support some of the features used in the code.
Errors in the book (Errors)
No matter how much the author is used to check the mistakes in the inspection, it will inevitably miss it. If you are confident that a mistake in the book is found, please contact the author, thank you.