21st Century C: C Tips from the New School
Ben Klemens
Language: English
Pages: 408
ISBN: 1491903899
Format: PDF / Kindle (mobi) / ePub
Throw out your old ideas about C and get to know a programming language that’s substantially outgrown its origins. With this revised edition of 21st Century C, you’ll discover up-to-date techniques missing from other C tutorials, whether you’re new to the language or just getting reacquainted.
C isn’t just the foundation of modern programming languages; it is a modern language, ideal for writing efficient, state-of-the-art applications. Get past idioms that made sense on mainframes and learn the tools you need to work with this evolved and aggressively simple language. No matter what programming language you currently favor, you’ll quickly see that 21st century C rocks.
- Set up a C programming environment with shell facilities, makefiles, text editors, debuggers, and memory checkers
- Use Autotools, C’s de facto cross-platform package manager
- Learn about the problematic C concepts too useful to discard
- Solve C’s string-building problems with C-standard functions
- Use modern syntactic features for functions that take structured inputs
- Build high-level, object-based libraries and programs
- Perform advanced math, talk to internet servers, and run databases with existing C libraries
This edition also includes new material on concurrent threads, virtual tables, C99 numeric types, and other features.
and using it from C, or just type sql tutorial into your favorite search engine. The basics are pretty simple. Here, I will focus on getting you started with the SQLite library itself. SQLite provides a database via a single C file plus a single header. That file includes the parser for SQL queries, the various internal structures and functions to talk to a file on disk, and a few dozen interface functions for our use in interacting with the database. Download the file, unzip it into your
depends on the standard math library. It seems that all the libraries are in the usual places, because there are no -L flags, but the -I flag indicates the special location for LibXML2’s header files. Back to the command line, the shell provides a trick that when you surround a command by backticks, then the command is replaced with its output. That is, when I type gcc `pkg-config --cflags --libs gsl libxml-2.0` -o specific specific.c the compiler sees: gcc -I/usr/include/libxml2 -lgsl
Those of you elbow-deep in numeric data may be interested in other ways we can use NaNs as markers. The IEEE standard has a lot of forms for NaN: the sign bit can be zero or one, then the exponent is all ones, and the rest is nonzero, so you have a bunch of bits like this: S11111111MMMMMMMMMMMMMMMMMMMMMMM, where S is the sign and M the unspecified mantissa. A zero mantissa indicates ±infinity, depending on the sign bit, but we can otherwise specify those Ms to be anything we want. Once we have
In contrast, if it says struct virtual_container *a; you can actually tell what a is.” The natural response to this is that it is having a longer name — and even one ending in container--that clarifies the code, not the word struct hanging at the beginning. But this typedef aversion had to come from somewhere. Further research turned up several sources that advise using typedefs to define units, e.g.: typedef double inches; typedef double meters; inches length1; meters length2; Now you have
literate coding style, this should be very readable; even if you’re in the habit of skipping big blocks of code, maybe give it a skim. If you have CWEB on hand, you can generate the PDF documentation and try reading it in that format. First, the header. What I call the join and exit functions might more commonly be read as the copy and free functions. The group_s structure has a size element, which is the number of group members — the reference count. You can see that I use Apophenia and Glib.