You are previewing 21st Century C.
O'Reilly logo
21st Century C

Book Description

Throw out your old ideas of C, and relearn a programming language that’s substantially outgrown its origins. With 21st Century C, you’ll learn how to dump old habits that made sense on mainframes, and pick up the tools you need to use this evolved and aggressively simple language.

Table of Contents

  1. 21st Century C
  2. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  3. A Note Regarding Supplemental Files
  4. Preface
    1. C Is Punk Rock
    2. Q & A (Or, the Parameters of the Book)
    3. Standards: So Many to Choose From
      1. The POSIX Standard
    4. Some Logistics
      1. Conventions Used in This Book
      2. Using Code Examples
      3. Safari® Books Online
      4. How to Contact Us
      5. Acknowledgments
  5. I. The Environment
    1. 1. Set Yourself Up for Easy Compilation
      1. Use a Package Manager
      2. Compiling C with Windows
        1. POSIX for Windows
        2. Compiling C with POSIX
        3. Compiling C Without POSIX
      3. Which Way to the Library?
        1. A Few of My Favorite Flags
        2. Paths
        3. Runtime Linking
      4. Using Makefiles
        1. Setting Variables
        2. The Rules
      5. Using Libraries from Source
      6. Using Libraries from Source (Even if Your Sysadmin Doesn’t Want You To)
      7. Compiling C Programs via Here Document
        1. Include Header Files from the Command Line
        2. The Unified Header
        3. Here Documents
        4. Compiling from stdin
    2. 2. Debug, Test, Document
      1. Using a Debugger
        1. GDB Variables
        2. Print Your Structures
      2. Using Valgrind to Check for Errors
      3. Unit Testing
        1. Using a Program as a Library
        2. Coverage
      4. Interweaving Documentation
        1. Doxygen
          1. The narrative
        2. Literate Code with CWEB
      5. Error Checking
        1. What Is the User’s Involvement in the Error?
        2. The Context in Which the User Is Working
        3. How Should the Error Indication Be Returned?
    3. 3. Packaging Your Project
      1. The Shell
        1. Replacing Shell Commands with Their Outputs
        2. Use the Shell’s for Loops to Operate on a Set of Files
        3. Test for Files
        4. fc
      2. Makefiles vs. Shell Scripts
      3. Packaging Your Code with Autotools
        1. An Autotools Demo
        2. Describing the Makefile with makefile.am
          1. Form variables
          2. Content variables
          3. Adding testing
          4. Adding makefile bits
        3. The configure Script
          1. More Bits of Shell
    4. 4. Version Control
      1. Changes via diff
      2. Git’s Objects
        1. The Stash
      3. Trees and Their Branches
        1. Merging
        2. The Rebase
      4. Remote Repositories
    5. 5. Playing Nice with Others
      1. The Process
        1. Writing to Be Read by Nonnatives
        2. The Wrapper Function
        3. Smuggling Data Structures Across the Border
        4. Linking
      2. Python Host
        1. Compiling and Linking
        2. The Conditional Subdirectory for Automake
        3. Distutils Backed with Autotools
  6. II. The Language
    1. 6. Your Pal the Pointer
      1. Automatic, Static, and Manual Memory
      2. Persistent State Variables
      3. Pointers Without malloc
        1. Structures Get Copied, Arrays Get Aliased
        2. malloc and Memory-Twiddling
        3. The Fault Is in Our Stars
        4. All the Pointer Arithmetic You Need to Know
          1. Typedef as a teaching tool
    2. 7. C Syntax You Can Ignore
      1. Don’t Bother Explicitly Returning from main
      2. Let Declarations Flow
        1. Set Array Size at Runtime
      3. Cast Less
      4. Enums and Strings
      5. Labels, gotos, switches, and breaks
        1. goto Considered
        2. switch
      6. Deprecate Float
    3. 8. Obstacles and Opportunity
      1. Cultivate Robust and Flourishing Macros
        1. Preprocessor Tricks
      2. Linkage with static and extern
        1. Declare Externally Linked Elements Only in Header Files
      3. The const Keyword
        1. Noun-Adjective Form
        2. Tension
        3. Depth
        4. The char const ** Issue
    4. 9. Text
      1. Making String Handling Less Painful with asprintf
        1. Security
        2. Constant Strings
        3. Extending Strings with asprintf
      2. A Pæan to strtok
      3. Unicode
        1. The Encoding for C Code
        2. Unicode Libraries
        3. The Sample Code
    5. 10. Better Structures
      1. Compound Literals
        1. Initialization via Compound Literals
      2. Variadic Macros
      3. Safely Terminated Lists
      4. Foreach
      5. Vectorize a Function
      6. Designated Initializers
      7. Initialize Arrays and Structs with Zeros
      8. Typedefs Save the Day
        1. A Style Note
      9. Return Multiple Items from a Function
        1. Reporting Errors
      10. Flexible Function Inputs
        1. Declare Your Function as printf-Style
        2. Optional and Named Arguments
        3. Polishing a Dull Function
      11. The Void Pointer and the Structures It Points To
        1. Functions with Generic Inputs
        2. Generic Structures
    6. 11. Object-Oriented Programming in C
      1. What You Don’t Get (and Why You Won’t Miss It)
        1. Scope
          1. Private struct elements
        2. Overloaded with Operator Overloading
          1. _Generic
      2. Extending Structures and Dictionaries
        1. Extending a Structure
          1. C, with fewer seams
        2. Implementing a Dictionary
        3. Base Your Code on Pointers to Objects
      3. Functions in Your Structs
      4. Count References
        1. Example: A Substring Object
        2. An Agent-Based Model of Group Formation
    7. 12. Libraries
      1. GLib
      2. POSIX
        1. Using mmap for Gigantic Data Sets
        2. Easy Threading with Pthreads
          1. The pthreads checklist
          2. Protect threaded resources with mutexes
          3. The example
          4. _Thread_local and static variables
      3. The GNU Scientific Library
      4. SQLite
        1. The Queries
      5. libxml and cURL
  7. Epilogue
  8. Glossary
  9. Bibliography
  10. Index
  11. About the Author
  12. Colophon
  13. SPECIAL OFFER: Upgrade this ebook with O’Reilly
  14. Copyright