C Standard Library "Bible": C standard library

Source: Internet
Author: User
Tags mathematical functions

C Standard Library "Bible": C standard library

[Author] (beauty) p. j. plauger [same as the author's work] [Translator's introduction]
[Translated by] Lu Hongxing; Xu Mingliang; Huo jiantong [same translator's work]
[Book name] Turing programming Series
[Release news agency] People's post and telecommunications Publishing House [book no.] 9787115172860
[Mounting time]
[Publication date] May July 2009 [Opening] 16

Market Price: ¥79.00
Member price: ¥59.25 (off)

Online Booking and sample chapter trial http://www.china-pub.com/195624

[Edit recommendations]
C. The standard library "Bible ".
Provides complete source code to thoroughly describe the implementation and application of library functions ..
C programmer's reference books...

[Content Overview]
This book is a classic C standard library written by world-class C language experts. The English version has been reprinted more than 10 times, affecting several generations of programmers ..

This book, in conjunction with the relevant parts of the C standard, tells the detailed usage and implementation of each library function, which is exactly what a real C programmer must master. More importantly, the book provides the complete source code for implementing and testing these functions, allowing you to learn more about the C language. Furthermore, this book also discusses some knowledge that even the most experienced C programmers are not familiar, for example, writing programs that are internationalized and independent from Region settings, concepts and design ideas related to build libraries ....

Preface
This book will show you how to use library functions that comply with the ANSI/ISO standards of the C language. Because many books have already explained the C language well, this book only focuses on the "library" topic. This book will also tell you how the C standard library is implemented. This book provides about lines of tested code that can actually work. I believe that after reading the implementation details of the C standard library, you can better understand how to use it.
The implementation code of library functions should use standard C as much as possible, so there are three designs: First, it makes the code readable and exemplary; second, it makes code highly portable between various computer architectures. Finally, it can make the written code take into account correctness, performance and scale.
It is not the purpose of this book to teach you how to write C Programs. This book assumes that you can understand simple C Programs. I will explain the difficulties and skills for the code that is slightly difficult.
C Standard Library
The C standard library is very powerful and provides a considerable number of features in different environments: it allows users and implementers to use clearly defined namespaces; it has strict requirements on the robustness and accuracy of the mathematical functions it provides. It is the first to provide support for codes that adapt to different cultural habits, including cultural habits with large character sets.
In order to effectively use the powerful functions provided by the standard library, you should understand many obscure details on its implementation. The real-time users of the library must provide these details to users so that they can better use the standard library. C standards do not clearly describe these obscure implementation details, because the main purpose of standards development is not to provide guidance to the database implementers. The rationale released together with the ansi c standard does not provide a good explanation of these details. Rationale has a wide range of objects to serve, and the standard implementers that focus on these details are only part of the numerous objects of service.
The new features mentioned above cannot be found in the traditional implementation of C. The current implementation can support the concept of locale in international development. Each region setting corresponds to a specific habit of a specific country, language, or occupation. a c program can dynamically adapt to multiple cultures by modifying and querying the region settings. The current implementation also supports a large number of character sets, such as a large number of Chinese characters. C Programs can process them as multibyte character or wide character. It can also be converted between the two forms. In the rapidly increasing market competition, this makes programming easier and more standard.
Because there was almost no corresponding programming art for these new features in the past, even the most experienced C programmers need some guidance when using regional settings, multi-byte characters, and wide-byte characters. Therefore, these topics have been given special attention here.
Details
This book explains the design intent and possible usage of the library to users and implementers. By providing the actual implementation of all library functions in the C standard library, this book uses examples to show you how to deal with its details. Where it is not clear that it is the best way to implement it, it also discusses options available and alternative.
An example involving details is the function getchar. In principle, the header file <stdio. h> can use the following macro to block the function declaration:
# Define getchar () fgetc (stdin)/* not wise! */
However, it should not do this. A reasonable (even if not used) C program is
# Include <stdio. h> # UNDEF fgetc
Int main (void) {int fgetc = getchar ();/* produces a mysterious Error */
Return (0 );
}
Of course, this example is a bit extreme, but it illustrates the mistakes that even a good programmer may make. Users have the right to request as few such strange errors as possible, so designers are obligated to avoid such strange errors.
The final form of getchar macro is
# Define getchar () (_ FILES [0]-> _ next <_ FILES [0]-> _ REND \? * _ FILES [0]-> _ next ++: (getchar )())
It is much different from the obvious (and more readable) format given for the first time above. Chapter 1 explains the causes.
Library Design
This book also aims to teach programmers how to design and implement libraries from a general perspective. Essentially, the library provided by the programming language is a hybrid "bag ". The database implementers must have a wide range of skills to handle all kinds of content in the bag. It is not enough to be a competent numeric analyst, be skillful and efficient in operating strings, or be familiar with many operating system interfaces. Writing a database requires both the above capabilities and more knowledge.
There are already many good books that tell you how to write mathematical functions, and many books that specifically introduce a library for a specific purpose. These tell you how to use the existing library. Some books even prove the correctness of the various design schemes of a database. Few books are dedicated to telling readers the skills required to build a database comprehensively.
Reusability
Many books have introduced general principles for designing and implementing software. The methods mentioned in these books include structured analysis, structured design, object-oriented design, and structured programming. Most examples in these books only consider programs written for an application. However, these principles and methods also apply to the implementation of reusable libraries.
However, the reusability goal further increases the requirement. From the perspective of structural design, if a library function does not have a high cohesion, it is unlikely to have a new purpose. Similarly, if it does not have low coupling, it will be more difficult to use. To put it simply, the library function must hide its implementation details and provide complete functions. Otherwise, from the object-oriented perspective, they cannot implement reusable data abstraction.
Therefore, the ultimate goal of this book is to discuss the specific design and implementation issues of the build library. The design of the C standard library is fixed. However, it is a good design in many aspects and deserves discussion. The implementation of the C standard library can also have many choices. Any choice must follow certain principles, such as correctness and maintainability. Other options also follow a specific project priority, such as high performance, portability, or small scale. These choices and principles are also worth discussing.
Structure of this book
The structure of this book basically corresponds to the C standard library itself. The 15 header files in the standard library declare or define all the names in the library. Each chapter in this book describes a header file. Most header files have compact content, which is also discussed in the book. However, one or two of them are very general, and their corresponding chapters will naturally involve more content.
In each chapter of this book, I have extracted the relevant sections of the ISO C standard. (Except for the format details, the ISO and ansi c standards are exactly the same .) These excerpts supplement how each part of the database is normally used. They also make this book a more complete reference manual (of course this book is easier to understand than reading C standards separately ). This book also provides the code for implementing those parts and testing these implementations.
Each chapter ends with references and related exercises. If this book is used as a university textbook, these exercises can be used as homework. Many exercises are just simple code rewriting. They can make some reasonable modifications to a specific knowledge point or indicate the implementation. All the more challenging questions are marked and can be used as the basis for those long-term projects, while the self-study can regard these exercises as the entry point for deep thinking.
Code
The code in this book has been tested in Borland, GNU project, and C compiler of VAX Ultrix. It has passed the tests of library functions of the widely used plum Hall validation suite and public domain programs designed specifically for C implementation to discover defects of C implementation. Although I try my best to minimize errors, I still cannot ensure that the Code is completely correct.
Note that the code in this book is copyrighted. It is neither placed in a public domain nor shared software. Unlike the Code released by the Free Software Foundation (GNU Project), it is not protected by the Copyleft protocol. I reserve all rights to this book.
Rational Use
You can convert the code in the book into an electronic version for personal use. You can also purchase machine-identifiable code from the C user group in loulunth, Kansas. In either case, your use of code must comply with the "rational use" provisions of the Copyright Law. Reasonable Use does not allow you to publish copies of these codes in any form, whether printed or electronic, free or paid.
In addition to the above, I allow reasonable use of a range of important uses. You can compile parts of the library and connect the generated binary target module with your own code to generate executable files. Unlimited publishing of such executable files is allowed. I do not require any rights for such copies. However, I strongly demand that you declare the existence of the Library (in your file), no matter how much you use, whether it has been modified or not modified. Please include the following text somewhere in the executable file: "part of the code in this file comes from the Standard C library, copyright (c) 1992 by P. j. plauger, published by Prentice-Hall, which is authorized for use." The document published along with the executable file should also be highlighted in appropriate places. If you omit any content, it will be deemed as infringement.
License
You can also be authorized to do more. You can publish the entire library in the form of a binary target module, or even publish copies of the source files in this book, whether or not they have been modified. Simply put, you can merge the entire library into a product that allows people to use it to write executable programs. However, all of these require a license. You can purchase a license. If you want to purchase a license and continuously obtain database support, contact plum Hall in kamaila, Hawaii.
Although the above sections have strong commercial colors, my main goal is not to promote a commercial product. I highly trust the C standard and have made great efforts to participate in its formulation. I spent a lot of energy developing C standard library specifications. I want to prove that we have created a good language standard. Write this implementation and this book to illustrate this simple but important fact.
Thank you
Compass in wekfield, Massachusetts, trusts me very much before the book is complete. They are the first users of my library code. They help me test, debug, and improve the library code when used on the intel 860 compiler. Ian wells, in particular, is willing to endure my delays and modifications, reflecting his professionalism. Mr. Don Anderson sacrificed a lot of rest time to email me to make the database structure more reasonable. I sincerely thank every colleague of compass for his sincerity and patience.
Paul Becker, publisher of Prentice-Hall, is also confident in this book. His gentle and unremitting encouragement is a guarantee for the completion of this book. He invited anonymous reviewers to help me clarify my point of view and reduce the absolute statements. Paul's professionalism made me understand why Prentice-Hall has been brilliant in the technology publishing field for so many years.
I moved to Australia during my writing, and this project is facing many difficulties. My good friend John o'brien, a business partner of Australian White Smiths, often helped me. He is a good hand to turn the thorns into roses. He has helped me a lot, not the word friendship.
Thanks to Andrew Binnie, Prentice Hall's release manager, for providing me with the laser printer used to complete this book. He is happy to help me in many ways. I would like to thank the University of New South Wales's Computer Science Department for providing me with time and places, even though they need to complete their own plans.
Tom Plum has always warned us to have a deep understanding of the basics of C. I have also benefited a lot from my discussions with him on the topics covered in this book. Dave Prosser also shared his profound insights on the way C works with me. As an ANSI and Iso c Standard editor, Dave provides a large number of electronic texts in this book. Hiroshi fukutomi and Takashi Kawahara, two principal directors of Tokyo's Senior Data Control Company (who took the lead in providing support for Chinese Characters in Japanese), learned about the technical needs of Japanese programmers, it helped me a lot.
Most of the materials here have been posted on the C users journal. Robert Ward is an easy-to-get-along publisher. I am very grateful to him for allowing me to reuse the materials. I would also like to thank Jim Brodie for allowing me to use the content in our co-authored Standard C book.
Reading technical books is a very boring task. John o'brien and Tom plum reviewed part of the book and provided valuable information. People who found the first printed version (only a small part) were wrong: Nelson H. F. Beebe, Peter Chubb, Stephen D. clamage, Steven Pemberton, Tom plum, and Ian Lance Taylor.
Finally, I would like to thank my family for their support. My son Geoffrey has done a lot of work in the text and page design of this book. My wife, Tana, provided me with great spiritual support and logistical support over such a long period of time. Their participation makes my writing process fun.
P. J. plauger
Bondy, New South Wales

Directory
Chapter 4 Introduction ..................................... .................... 1
0.1 background ..................................... ................... 1
0.2 C standard content ................................... ............. 3
0.3 use of the database .................................... .................... 7
0.4 library implementation .................................... .................... 9
0.5 database test .................................... .................. 13
0.6 references ..................................... ................. 15
0.7 exercise ...................................... ........................ 15
Chapter 2 <assert. h> ...................................... .. 17
1.1 Background ..................................... ................. 17
1.2 C standard content ................................... ........... 18
1.3 <assert. h> usage .................................. 18
1.4 <assert. h> Implementation .................................. 20
1.5 <assert. h> test .................................. 22
1.6 references ..................................... ................. 23
1.7 exercise ...................................... ........................ 23
Chapter 2 <ctype. h> ...................................... .... 25
2.1 Background ..................................... ................. 25
2.2 C standard content ................................... ........... 28
2.3 <ctype. h> usage .................................... 30
2.4 <ctype. h> Implementation .................................... 34
2.5 <ctype. h> test .................................... 42
2.6 references ..................................... ................. 45
2.7 exercise ...................................... ........................ 45
Chapter 2 <errno. h> ...................................... .... 47
3.1 Background ..................................... ................. 47
3.2 c Standard content ................................... ........... 50
3.3 <errno. h> usage .................................... 50
3.4 <errno. h> Implementation .................................... 51
3.5 <errno. h> test .................................... 55
3.6 references ..................................... ................. 55
3.7 exercise ...................................... ........................ 55
Chapter 2 <float. h> ......................................... 57
4.1 background ..................................... ................. 57
4.2 C standard content ................................... ........... 59
4.3 <float. h> usage ..................................... 62
4.4 <float. h> Implementation ..................................... 64
4.5 <float. h> test ..................................... 69
4.6 references ..................................... ................. 71
4.7 exercise ...................................... ........................ 72
Chapter 2 <limits. h> ...................................... .. 73
5.1 background ..................................... ................. 73
5.2 C standard content ................................... ........... 74
5.3 <limits. h> usage .................................. 75
5.4 <limits. h> Implementation .................................. 77
5.5 <limits. h> test .................................. 79
5.6 references ..................................... ................. 80
5.7 exercise ...................................... ........................ 80
Chapter 2 <locale. h> ...................................... .. 81
6.1 background ..................................... ................. 81
6.2 C standard content ................................... ........... 84
6.3 <locale. h> usage .................................. 87
6.4 <locale. h> Implementation .................................. 94
6.5 <locale. h> test ................................ 123
6.6 references ..................................... ............... 123
6.7 exercise ...................................... ...................... 123
Chapter 2 <math. h> ...................................... ..... 127
7.1 background ..................................... ............... 127
7.2 C standard content ................................... ......... 130
7.3 <math. h> usage .................................... 135
7.4 <math. h> Implementation .................................... 137
7.5 <math. h> test .................................... 171
7.6 references ..................................... ............... 177
7.7 exercise ...................................... ...................... 177
Chapter 2 <setjmp. h> .................................... 181
8.1 background ..................................... ............... 181
8.2 C standard content ................................... ......... 184
8.3 <setjmp. h> usage ................................ 185
8.4 <setjmp. h> Implementation ................................ 187
8.5 <setjmp. h> test ......
8.6 references ..................................... .............. 192
8.7 exercise ...................................... ..................... 192
Chapter 2 <signal. h> .................................... 193
9.1 background ..................................... ............... 193
9.2 C standard content ................................... ......... 195
9.3 <signal. h> usage ................................ 197
9.4 <signal. h> Implementation ................................ 199
9.5 <signal. h> test ................................ 203
9.6 references ..................................... ............... 203
9.7 exercise ...................................... ...................... 203
Chapter 2 <stdarg. h> ................................. 205
10.1 Background ..................................... ............. 205
10.2 C standard content ................................... ....... 207
10.3 <stdarg. h>
10.4 <stdarg. h>
10.5 <stdarg. h> test ......
10.6 references ..................................... ............. 212
10.7 exercise ...................................... .................... 214
Chapter 2 <stddef. h> ................................. 215
11.1 background ..................................... ............. 215
11.2 C standard content ................................... ....... 217
11.3 <stddef. h>
11.4 <stddef. h>
11.5 <stddef. h> test ......
11.6 references ..................................... ............. 223
11.7 exercise ...................................... .................... 223
Chapter 2 <stdio. h> ...................................... 225
12.1 Background ..................................... ............. 225
12.2 C standard content ................................... ....... 233
12.3 <stdio. h> usage ................................ 252
12.4 <stdio. h> Implementation ................................ 274
12.5 <stdio. h> test ................................ 323
12.6 references ..................................... ............. 325
12.7 exercise ...................................... .................... 325
Chapter 2 <stdlib. h> ................................... 331
13.1 Background ..................................... ............. 331
13.2 C standard content ................................... ....... 332
13.3 <stdlib. h>
13.4 <stdlib. h>
13.5 <stdlib. h> test ......
13.6 references ..................................... ............. 379
13.7 exercise ...................................... .................... 382
Chapter 2 <string. h> ................................... 385
14.1 Background ..................................... ............. 385
14.2 C standard content ................................... ....... 386
14.3 <string. h>
14.4 <string. h>
14.5 <string. h> test... 409
14.6 references ..................................... ............. 409
14.7 exercise ...................................... .................... 409
Chapter 2 <time. h> ....................................... 413
15.1 background ..................................... ............. 413
15.2 C standard content ................................... ....... 414
<Time. 15.3. h> usage ................................... 418
<Time. 15.4. h> Implementation ................................... 422
<Time. 15.5. h> test .................................. 440
15.6 references ..................................... ............. 441
15.7 exercise ...................................... .................... 441
Appendix A interface ..................................... ................. 443
Appendix B Name ...................................... ................ 451
Appendix C terminology ..................................... ................. 461

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.