ANSI-C Object-Oriented Programming
Preface
No omnipotent Programming Technology
No programming language that generates only the correct results
Not every project's programming starts from scratch.
Object-Oriented Programming is almost a solution today-although it has been developing for more than 10 years. As a core language, some technical experts have paid a lot for its research, thus forming good programming rules that we have been learning for 20 years. C ++ (Eiffel, Oberon-2, Smalltalk...
Choose from) is a new programming language, because it is object-oriented-although you don't need to use it, maybe you don't want to use it (or you don't know how to use it ), but you can use ordinary ANSI-C
(Standardization) is as convenient as using these object-oriented languages. In a project, only object-oriented languages allow code reuse-although some subprograms have the same idea as the history of computer development, good programmers always use the toolbox or library to use these subprograms.
This book is not intended to praise object-oriented programs or criticize old programming rules. We simply use ANSI-C to find out how object-oriented language is implemented, what is the technical method, why it can help us solve the bigger problem, and how we can use universal methods and programming to capture errors earlier. Along with this purpose, we will encounter some things-class, inheritance, instances, links, methods, objects, polymorphism, and so on-but we can just remove its magic coat, let's look at how it turns into something we have always known and done.
I would love to explore ANSI-C (Standardization) as a comprehensive object-oriented language. In order to be able to share this fun, before you start, you need the right ANSI-C
Have a certain degree of fluency-it is necessary to be familiar with structures, pointers, prototypes, and function pointers. Throughout the full text, you will meet all new ideas
-In the words of Orwell and Webster, "design is to narrow down the breadth of thinking"-and I will try my best to prove how it works with all the good methods and results you 've always wanted to use continuously, you are likely to become a programmer proficient in ANSI-C.
The first six chapters establish the foundation of ANSI-C object-oriented programming. We will start with a very precise information that hides the abstract data structure, and then add feature Attributes Based on Dynamic Links and code inheritance through struct extension. Finally, they are put together to form an inherited class, making the code easier to maintain.
Rules are required for programming. Good Programs follow many rules, a large number of rules, standards, and self-defense methods. Programmers must learn to use tools. Excellent programmers write tools to process routine programming routines. ANSI-C
Object-oriented Programs require a certain amount of fixed code
-The name is changed, and the data structure is not changed. Therefore, in Chapter 7 we have created a small Preprocessor to create a required template, which is more like another new object-oriented language (maybeYanoodl) But it is not so taken into consideration that OOC (Object-Oriented Programming ANSI-C) is new and new, allowing us to focus on using creative techniques in solving problems. OOC has strong plasticity. We designed it, understood it, and changed it to write ANSI-C code as we wanted.
Our technology will be refined in the following sections. In section 8, we add a dynamic type check to pre-capture exceptions. In chapter 9, an automatic initialization mechanism is provided to prevent other defects. Chapter 10 describes polymorphism and how to collaborate with each other to simplify the process. For example, daily transactions of the standard master program are generated. More sections will be associated with the use of class methods, storage, and loading of struct data, which follow the consistency policy. In addition, consistent error recovery is achieved through nested exception processor systems.
Finally, in the last chapter, we avoided the limitations of ANSI-C and implemented a calculator for mouse operations, first
Curses
Terminal, then apply to X Window
System (if you want to know something about curses
And X Window
For more information, see ).
This example clearly demonstrates the design we use classes and objects for and the beauty of the instance, although we have to deal with external library and class hierarchy features.
There is a brief description before each chapter. In this summary, I will give an outline to introduce the main content of the chapter and what to do next, this is helpful for readers who have skipped this chapter. We recommend that you do some exercises in most sections, but this does not mean it is very formal, because we have built such a technology from scratch. I have avoided creating and using large class libraries, even if some examples seem advantageous. If you want to better understand object-oriented programming, it is especially important to master this technology and consider code design. Relying on other people's class libraries for development is a piece of cake later.
An important part of this book is the attachment of a code floppy disk ----
The DOS file system contains a separate shell to create the code in all the chapters. There is a ReadMe on the floppy disk.
File ---- read the code before generating it. Programming is like using
Diff program, tracking the evolution of the base class will be very good for you. OOC will be well reflected in the following chapters.
The descriptions of these technologies come from my awareness of C ++, when I need to use object-oriented technology to implement interactive programming languages. And realize that a portable instance cannot be created in C ++. I turn to what I know, that is, ANSI-C, that I can do exactly what I have to do. I have already shared this technology with many people, including my workplace. Other people have used these methods to complete their work. This book is here, because the footer is particularly gloomy to me. Brian
Kernighan, my publishing house, Hans-Joachim niclas and John, etc. They didn't encourage me to publish these notes (I have the opportunity to organize them again when appropriate ), I would like to thank them and those who helped me continue this book. Finally, I would like to thank my family -- and, no, the object-oriented mechanism will not replace "slice ".
Hollage, October 1993
Axel-Tobias Schreiner