Hacktical C: A Practical Guide Sparks Debate on C's Role in Modern Programming

BigGo Editorial Team
Hacktical C: A Practical Guide Sparks Debate on C's Role in Modern Programming

In an era dominated by memory-safe languages and high-level abstractions, a new open-source book titled Hacktical C has emerged, positioning itself as a practical hacker's guide to the C programming language. Released under an open license, the book has sparked intense discussions within the programming community about C's relevance, safety, and position in the modern programming ecosystem.

C as Portable Assembly - Myth or Reality?

One of the most contentious points in the community discussion revolves around the author's claim that C stands in a class of its own as a mostly portable assembler language. This characterization has been met with significant pushback from developers who argue that C is far from being a true low-level language by modern standards.

When your computer is a PDP-11, otherwise it is a high level systems language like any other.

Several commenters point out that C actually creates an abstract machine that doesn't directly map to modern hardware capabilities. When writing C code, developers are programming for a virtual machine described by the C specification rather than the actual hardware. This abstraction includes behaviors that don't exist in physical hardware, such as undefined behavior around signed overflow and memory initialization tracking. Furthermore, critics note that C lacks native support for many hardware features that have become standard over the past few decades, including proper bit manipulation for sub-byte values and straightforward SIMD operations.

Memory Safety and the Freedom with Responsibility Debate

The author's position that C doesn't try very hard to prevent you from making mistakes and offers freedom with responsibility has triggered substantial discussion about the real-world implications of this philosophy. While some commenters appreciate this approach, many challenge the notion that memory-unsafe languages are a viable choice for modern software development.

Critics argue that memory safety issues aren't simply a matter of programmer skill but represent systematic vulnerabilities that continue to produce security exploits regardless of developer expertise. They point out that no amount of individual programming prowess has meaningfully reduced the rate of CVEs caused by memory safety bugs in C programs. The debate extends to whether the flexibility offered by C is worth the security and maintenance costs, especially when modern languages with unsafe escape hatches (like Rust) can provide both safety and performance.

Practical C Techniques: Clever Hacks or Dangerous Patterns?

The book itself showcases various C programming techniques, some of which have generated both admiration and concern. One example that caught particular attention is a coroutine implementation using the __LINE__ macro in a creative way:

 Key Topics in Hacktical C

* Macros
* Fixed-Point Arithmetic
* Intrusive Doubly Linked Lists
* Lightweight Concurrent Tasks
* Composable Memory Allocators
* Vectors
* Exceptions
* Ordered Sets and Maps
* Dynamic Compilation
* Extensible Streams
* Structured Logs

 C Language Support by Compiler

| Compiler | C17 | C11 | VLAs | C23 |
|----------|-----|-----|------|-----|
| GCC      | Yes | Yes | Yes  | Yes (default) |
| Clang    | Yes | Yes | Yes  | Partial |
| MSVC     | Yes (since 2020) | Yes | No (never planned) | Unclear roadmap |

#define hc_task_yield(task)   
  do {     
    task->state = __LINE__;   
    return;     
    case __LINE__:;           
  } while (0)

While some commenters found this technique diabolical yet clever, others pointed to alternative implementations and discussed the merits of using GNU extensions versus standard C. This highlights the book's focus on practical, sometimes unconventional approaches to solving problems in C.

Microsoft's Relationship with C

The book's assertion that Microsoft has unfortunately chosen to neglect C for a long time, its compilers dragging far behind the rest of the pack prompted a discussion about the current state of Microsoft's C support. Commenters clarified that while Microsoft has historically prioritized C++ over C, there have been improvements in recent years. In 2020, Microsoft added support for C11 and C17 standards, though some features like Variable Length Arrays (VLAs) remain unsupported with no plans for implementation. The community remains uncertain about Microsoft's roadmap for C23 support, especially given the company's increasing focus on memory-safe languages as part of its security initiatives.

In a landscape increasingly dominated by discussions of memory safety and modern language features, Hacktical C represents both a practical resource for C programmers and a philosophical statement about programming language choice. Whether viewed as a valuable collection of techniques or a defense of an increasingly contested approach to systems programming, the book has certainly succeeded in generating thoughtful discussion about C's place in today's programming world.

Reference: Hacktical C