This Apress imprint is published by the registered company APress Media, LLC, part of Springer Nature.
The registered company address is: 1 New York Plaza, New York, NY 10004, U.S.A.
To Janet, yet again.
C is a small but extensible language, with software libraries (standard and third party) extending the core language. Among high-level languages, C still sets the mark for performance; hence, C is well suited for applications, especially ones such as database systems and web servers that must perform at a high level. The syntax for C is straightforward, but with an oddity here and there. Anyone who programs in a contemporary high-level language already knows much of C syntax, as other languages have borrowed widely from C.
C is also the dominant systems language: modern operating systems are written mostly in C, with assembly language accounting for the rest. Other programming languages routinely and transparently use standard library routines written in C. For example, when an application written in any other high-level language prints the Hello, world! greeting, it is a C library function that ultimately writes the message to the screen. The standard system libraries for input/output, networking, string processing, mathematics, security, cryptography, data encoding, and so on are likewise written mainly in C. To write a program in C is to write in the system’s native language.
should provide details. For Windows, Cygwin ( https://cygwin.com/install.html ) is recommended.
C has been a modern language from the start. The familiar function, which can take arguments and return a value, is the primary code module in C. C exhibits a separation of concerns by distinguishing between interfaces, which describe how functions are called, and implementations, which provide the operational details. As noted, C is naturally and easily extended through software libraries, whether standard or third party. As these libraries become better and richer, so does C. C programmers can create arbitrarily rich data types and data structures and package their own code modules as reusable libraries. C supports higher-order functions (functions that can take functions as arguments) without any special, fussy syntax. This book covers C’s modern features, but always with an eye on C’s close-to-the-metal features.
To understand C is to understand the underlying architecture of a modern computing machine, from an embedded device through a handheld up to a node in a server cluster. C sits atop assembly language, which is symbolic (human-understandable) machine language. Every assembly language is specific to a computer architecture. The assembly language for an Intel device differs from that of an ARM device. Even within an architectural family such as Intel, changes in the architecture are reflected in assembly language. As symbolic machine language, assembly language is approachable, although reading and writing assembly code can be daunting. Assembly language is of interest even to programmers in other languages because it reveals so much about the underlying system. C does not reveal quite as much, but far more than any other high-level language; C also reveals what is common across architectures. One sign of just how close C is to assembly language shows up in compilation: a C compiler can handle any mix of C and assembly source code, and C source is translated first into assembly code. From time to time, it will be useful to compare C source with the assembly source into which the C source translates.
C source code ports well: a C program that compiles on one platform should compile on another, unless platform-specific libraries and data structure sizes come into play. Perfect portability remains an ideal, even for C. C plays still another role—as the lingua franca among programming languages: any language that can talk to C can talk to any other language that does so. Most other languages support C calls in one form or another; a later code example shows how straightforwardly Python can consume library functions written in C.
Memory safety and efficiency: Best practices for using the stack, the heap, and static area of memory; techniques and tools for avoiding memory leakage
Higher-order functions: Simplifying code by passing functions as arguments to other functions
Generic functions: How to use the pointer-to-void (void*) data type in creating and calling generic functions
Functions with a variable number of arguments: How to write your own
Defining new data types: A convenient way to name programmer-defined, arbitrarily rich data types
Clarifying C code through assembly-language code: Getting closer to the metal
Embedding assembly code: Checking for overflow with embedded assembly
Floating-point issues: Code examples and the IEEE 754 specification in detail
Low-level and high-level input/output: Flexibility and performance trade-offs in input/output operations
Networking and wire-level security: Full code examples, including digital certificates and secure sockets
Nonblocking input/output: Local machine and networking examples of this acceleration technique
Concurrency and parallelism: Multiprocessing, interprocess communication, multithreading, deadlock, and instruction-level SIMD parallelism
Interprocess communication: Pipes (named and unnamed), message queues, sockets, file sharing and locking, shared memory with a semaphore, and signals
Data validation: Regular expressions in detail
Internationalization: Standard libraries for locale management
Assertions: Expressing and enforcing pre-, post-, and invariant conditions in programs
WebAssembly: Compiling C code into WebAssembly for high-performance web modules
Software libraries: How to build and deploy both static and dynamic software libraries for C and non-C clients
The code examples in the book are available at https://github.com/mkalin/cbook.git , and comments are welcome at [email protected].
My hearty thanks go to the Apress people who made this book possible. I would like to thank, in particular, the following: Steve Anglin, Associate Editorial Director of Acquisitions; Jill Balzano, Coordinating Editor; and James Markham, Development Editor. Thanks as well to the technical reviewers who made the book better than it otherwise would have been.
has a Ph.D. from Northwestern University and is a professor in the College of Computing and Digital Media at DePaul University. He has cowritten a series of books on C and C++ and written a book on Java web services. He enjoys commercial programming and has codeveloped, in C, large distributed systems in process scheduling and product configuration. He can be reached at http://condor.depaul.edu/mkalin .
is a polyglot Software Architect/Engineer with 20+ years in the field, with knowledge in Java, Spring, C, Julia, Python, Haskell, and JavaScript, among others. He works for cloud, web distributed applications. Germán loves math puzzles (including reading Knuth), swimming, and table tennis. Also, he has reviewed several books including an application container book (Weblogic) and some books on languages (Haskell, TypeScript, WebAssembly, Math for coders, regexp, Julia, Algorithms). For more details, visit his blog ( https://devwebcl.blogspot.com/ ) or Twitter account: @devwebcl.
18.221.239.148