You are previewing 21st Century C.

21st Century C

Cover of 21st Century C by Ben Klemens Published by O'Reilly Media, Inc.
  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
      3. Which Way to the Library?
      4. Using Makefiles
      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
    2. 2. Debug, Test, Document
      1. Using a Debugger
      2. Using Valgrind to Check for Errors
      3. Unit Testing
      4. Interweaving Documentation
      5. Error Checking
    3. 3. Packaging Your Project
      1. The Shell
      2. Makefiles vs. Shell Scripts
      3. Packaging Your Code with Autotools
    4. 4. Version Control
      1. Changes via diff
      2. Git’s Objects
      3. Trees and Their Branches
      4. Remote Repositories
    5. 5. Playing Nice with Others
      1. The Process
      2. Python Host
  6. II. The Language
    1. 6. Your Pal the Pointer
      1. Automatic, Static, and Manual Memory
      2. Persistent State Variables
      3. Pointers Without malloc
    2. 7. C Syntax You Can Ignore
      1. Don’t Bother Explicitly Returning from main
      2. Let Declarations Flow
      3. Cast Less
      4. Enums and Strings
      5. Labels, gotos, switches, and breaks
      6. Deprecate Float
    3. 8. Obstacles and Opportunity
      1. Cultivate Robust and Flourishing Macros
      2. Linkage with static and extern
      3. The const Keyword
    4. 9. Text
      1. Making String Handling Less Painful with asprintf
      2. A Pæan to strtok
      3. Unicode
    5. 10. Better Structures
      1. 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
      9. Return Multiple Items from a Function
      10. Flexible Function Inputs
      11. The Void Pointer and the Structures It Points To
    6. 11. Object-Oriented Programming in C
      1. What You Don’t Get (and Why You Won’t Miss It)
      2. Extending Structures and Dictionaries
      3. Functions in Your Structs
      4. Count References
    7. 12. Libraries
      1. GLib
      2. POSIX
      3. The GNU Scientific Library
      4. SQLite
      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
O'Reilly logo

Chapter 7. C Syntax You Can Ignore

I believe it is good Let’s destroy it.

Porno for Pyros, “Porno for Pyros”

In the 1980s, the synthesizer became a common, viable tool for musicians. Now, it’s not hard to recognize music that made use of the then-new technology as being decidedly ’80s. A similar but somewhat more subtle thing happened with the drum machine in the late 1990s. Compare with dance music up to the swing era, which was all about horns that could carry in a music hall before we had all this electronic equipment amplifying the instruments.

There was a time when C was a cutting-edge language, intended to replace assembly code and compete with FORTRAN, COBOL, and other all-caps languages that have not withstood the test of time quite as well as C (which, when you think about it, also has an all-caps name). But looking at C code from the 1980s, you can tell it was written then.

This isn’t about stylistic details like where we put the curly braces. Yes, older code tends to be more sparse, like:

if (x > 0)
{
    return 1;
}

whereas scripting languages tend toward compressing these four lines into a one-line thought, like:

if (x > 0) return 1;

but I have no interest in telling you where to put your curly braces.

Rather, more fundamental features of C that made sense at the time have a real effect on the readability and maintainability of code. In many cases, the textbooks on the market haven’t been updated to mention some of the conveniences added to C in 1999, meaning that they do things ...

The best content for your career. Discover unlimited learning on demand for around $1/day.