Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
21st Century C
1. Preface: C is punk rock
Q & A [Or, the parameters of the book]
Standards: so many to choose from
The POSIX standard
Some logistics
Conventions Used in This Book
Using Code Examples
Safari® Books Online
How to Contact Us
Credits
I. The environment
2. Set yourself up for easy compilation
Use a package manager
Compiling C for Windows
POSIX for Windows
Compiling C with POSIX
Compiling C without POSIX
Which way to the library?
A few of my favorite flags
Paths
Run-time linking
Using makefiles
Setting variables
The rules
Using libraries from source
Using libraries from source (even if your sysadmin doesn’t want you to)
Compiling C programs via here document
Include header files from the command line
The unified header
Here documents
Compiling from stdin
3. Debug, test, document
Using a debugger
GDB variables
Print your structures
Use Valgrind to check for errors
Unit testing
Using a program as a library
Coverage
Interweaving documentation
Doxygen
The narrative
Literate code with CWEB
Error checking
What is the user’s involvement in the error?
The context in which the user is working
How should the error indication be returned?
4. Packaging your project
The shell
Replacing shell commands with their outputs
Use the shell’s for loops to operate on a set of files
Test for files
fc
Makefiles versus shell scripts
Packaging your code with Autotools
An Autotools demo
Describing the makefile in makefile.am
Form variables
Content variables
Adding testing
Adding Makefile bits
The configure script
More bits of shell
5. Version control
Changes via diff
Git’s objects
The stash
Trees and their branches
Merging
The rebase
Remote repositories
6. Playing nice with others
The process
Writing to be read by non-natives
The wrapper function
Smuggling data structures across the border
Linking
Python host
Compiling and linking
The conditional subdirectory for Automake
Distutils b/w Autotools
II. The language
7. Your pal the pointer
Static, automatic, manual memory
Persistent state variables
Pointers without malloc
Structures get copied, arrays get aliased
malloc and memory-twiddling
The fault is in our stars
All the pointer arithmetic you need to know
typedef as a teaching tool
8. C syntax you can ignore
Don’t bother explicitly returning from main()
Let declarations flow
Set array size at runtime
Cast less
Enums and strings
Labels, gotos, switches, and breaks
goto considered
Switch
Deprecate float
9. Obstacles and opportunity
Cultivate robust and flourishing macros
Preprocessor tricks
Linkage with static and extern
Declare externally linked elements only in header files
The const keyword
Noun-adjective form
Tension
Depth
The char const ** issue
10. Text
Making string handling less painful with asprintf
Security
Constant strings
Extending strings with asprintf
A pæan to strtok
Unicode
The encoding for C code
Unicode libraries
The sample code
11. Better structures
Compound literals
Initialization via compound literals
Variadic macros
Safely terminated lists
Foreach
Vectorize a function
Designated initializers
Initialize arrays and structs with zeros
Typedefs save the day
A style note
Return multiple items from a function
Reporting errors
Flexible function inputs
Declare your function as printf-style
Optional and named arguments
Polishing a dull function
The void pointer and the structures it points to
Functions with generic inputs
Generic structures
12. Object-oriented programming in C
What you don’t get (and why you won’t miss it)
Scope
Private struct elements
Overloaded with operator overloading
_Generic
Extending structures and dictionaries
Extending a structure
C, with fewer seams
Implementing a dictionary
Base your code on pointers to objects
Functions in your structs
Count references
Example: a substring object
An agent-based model of group formation
13. Libraries
Glib
POSIX
Using mmap for gigantic data sets
Easy threading with Pthreads
The pthreads checklist
Protect threaded resources with mutexes
The example
__Thread_local and static variables
The GNU Scientific Library
SQLite
The queries
libXML & cURL
14. Epilogue
Glossary
Bibliography
About the Author
Copyright
← Prev
Back
Next →
← Prev
Back
Next →