Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorJens Gustedt

Almost 50 years ago, the C language defined modern computer programming. This book shows you why C is still as powerful and popular as ever, with an inside look at the new C23 standard. For programs that need to be small, fast, and unfailingly reliable, C is still the gold standard. Whether you’re writing embedded code, low-level system routines, or high-performance applications, C is up to the challenge. This unique book by Jens Gustedt, a member of the ISO C standards committee, gets you up to speed with C23. In Modern C, Third Edition you’ll: Learn C basics, core features, and advanced concepts Leverage major C23 improvements for security, reliability, and performance Write portable code that runs anywhere

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Modern C (3rd Edition) — Reading Guide ## 【One-Line Pitch】 A standards-committee insider's guide to modern C programming, covering everything from core language fundamentals to the latest C23 improvements for writing safer, more portable, and higher-performance code. Essential reading for embedded developers, systems programmers, and anyone who needs C to be small, fast, and reliable. ## 【Book Arc】 - **Opening (~0%–10%)**: Sets up the C23 landscape, compiler setup (clang/gcc/icc with `-std=c2x`), and introduces the book's style conventions—left-binding type modifiers, array notation for pointer parameters, and why these choices improve readability and safety. - **Early (~10%–23%)**: Builds the foundation with scopes, blocks, and function parameters, then moves into arithmetic—overflow behavior, division/remainder semantics, and a practical Union-Find challenge that exercises core concepts. Type selection guidance (size_t, unsigned, signed, ptrdiff_t, double) is established here. - **Early-to-Middle (~23%–32%)**: Dives into C23's new features—`constexpr` for compile-time checked constants, macro best practices, and the critical distinction between well-defined behavior and undefined behavior (especially around signed arithmetic and traps). - **Middle (~39%–48%)**: Covers aggregates and type abstraction: structures with designated initializers, the new `_BitInt(N)` types for precise bit-field control, typedef aliases, and command-line argument conventions (`argv[0]`, `argv[argc]` being null). - **Late (~48%+)**: Transitions to the C standard library—its separation from the language proper, the API design that allows compiler/library independence (glibc vs musl on Linux), and checked arithmetic operations like `ckd_add` for overflow detection. ## 【Key Takeaways】 - **C23 is a modernization milestone** (Opening): The new standard brings `constexpr`, `_BitInt` types, and checked arithmetic—features that address security and reliability concerns without abandoning C's performance ethos. Compiler support varies, so check your toolchain's C23 readiness. - **Style conventions prevent real bugs** (Early): Left-binding type modifiers (`char* name` not `char *name`) and array notation for non-null pointer parameters (`char const string[static 1]`) make code self-documenting and catch null-pointer misuse at the type level. - **Unsigned types are your default for sizes and counts** (Early): They have mathematically consistent modulo arithmetic, can't raise overflow signals, and optimize best. Use `size_t` for sizes/cardinalities, `unsigned` for small non-negative quantities, and reserve signed types for values that genuinely need signs. - **`constexpr` gives compile-time safety** (Early): C23's `constexpr` validates that initializers fit exactly—a conversion losing precision becomes a compile error, not silent runtime corruption. This is a major improvement over macro-based constants. - **Signed arithmetic can trap badly** (Early): Negation can overflow (`INT_MIN < -INT_MAX`), and bit operations on negative values have murky semantics. Avoid signed arithmetic unless you truly need it; undefined behavior means the program has failed. - **`_BitInt(N)` enables precise bit-fields** (Middle): C23's new exact-width integer types let you define bit-fields with guaranteed behavior—no more implementation-defined widths. Use `bool` for 1-bit flags and `_BitInt(N)` for numerical fields of width N. - **The C library is separable from the language** (Late): The standard library's clear API allows mixing compilers and library implementations (gcc/clang with glibc/musl on Linux). Checked arithmetic functions like `ckd_add` detect overflow without the performance cost of manual checks. ## 【Reading Tips】 - **Skim the compiler setup section** if you're already comfortable with command-line compilation—just note the `-std=c2x` flag for C23 features. - **Deep-read the type selection guidance** (Takeaways 5.2 #3–#8): This is the book's practical core for writing correct, portable code. The rules are simple but the reasoning is subtle. - **Work through the Union-Find challenge** (Early): It's a genuine exercise that forces you to apply size_t, arrays, and algorithm design together—not just read about them. - **Pay special attention to the undefined behavior section** (Early): Understanding traps and why signed arithmetic is dangerous will save you from the most insidious C bugs. - **The style conventions section is worth adopting wholesale**—even if you disagree with some choices, consistency in type binding and pointer notation eliminates a whole class of declaration errors. ## 【Coverage Limits】 Excerpts cover roughly the first half of the book (through the standard library introduction). Later sections on advanced topics, program failure handling (section 15), and full library function groups are not covered in this guide. ##
Page 10
tainly for a more varied and fast-paced technological life. At a time when it is hard to tell one computer book from another, Manning celebrates the inventiv...
View in text
Excerpt 2
s like this: Terminal 0 > ./heron 0.07 5 6E+23 1 heron: a=7.00000e-02, x=1.42857e+01, a*x=0.999999999996 2 heron: a=5.00000e+00, x=2.00000e-01, a*x=0.9999999...
View in text
Excerpt 3
n converting to the type unsigned on the left. Takeaway 5.6.5 #1 The initializer of a constexpr must fit exactly. constexpr can also be used for compound lit...
View in text
Excerpt 4
m executable. Takeaway 7.2 #7 argv[argc] is a null pointer. In the argv array, the last argument could always be identified using this property, but this fea...
View in text
Excerpt 5
xplained in subsection 8.7. strftime receives three arrays: a char[max] array that is to be filled with the result string, another string that holds the form...
View in text
Excerpt 6
pe rat that is supposed to be used for rational arithmetic: This is a direct implementation of such a type, and nothing you should use as a library outside t...
View in text
Excerpt 7
e code (and if you are still here, you probably are), early errors in the development phase are really helpful.11 So, consider crashing a feature. See the bl...
View in text
Excerpt 8
ion that refers to an object outside of its lifetime fails. How the start and end points of an object are defined depends on the tools we use to create it. W...
View in text
Tags
AI categories
Programming LanguageCode
Publish Year: 2024
Language: English
Pages: 553
File Format: PDF
File Size: 9.7 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…