Jens Gustedt
gustedt.wordpress.com · Personal blog · on HN since 2012
Jens Gustedt, a C standards contributor, writes about the C language, upcoming C standard revisions, and the book Modern C.
What HN saysHN commenters recommend his Modern C book as an opinionated, sane guide for learning C, and cite his posts on unsigned loops and variably modified types.
52HN people shared it
21linked it in comments
71stories submitted
2.5Kstory points
9 months agolast shared
2012people per year2026
Most-shared posts
- 1A Defer Mechanism for C4 people · 187 points · first shared 2020 · 244 comments on HN
- 2C2x: the next real revision of the C standard4 people · 175 points · first shared 2018 · 184 comments on HN
- 3Modern C is now feature complete4 people · 127 points · first shared 2016 · 1 comments on HN
- 4A defer feature using lambda expressions4 people · 20 points · first shared 2022 · 1 comments on HN
- 5Don’t use casts4 people · 14 points · first shared 2014 · discussion on HN
- 6Contracts for C3 people · 118 points · first shared 2025 · 111 comments on HN
- 7Checked integer arithmetic in the prospect of C233 people · 8 points · first shared 2022 · 1 comments on HN
- 8Feature Freeze in C233 people · 4 points · first shared 2021 · discussion on HN
- 9Don't use fake matrices (2014)3 people · 3 points · first shared 2020 · discussion on HN
- 10Modern C, Second Edition2 people · 597 points · first shared 2019 · 233 comments on HN
- 11Cross Language interfaces between C and C++ (2017)2 people · 36 points · first shared 2018 · 11 comments on HN
- 12C17: a “bugfix release” of the C standard2 people · 21 points · first shared 2018 · 1 comments on HN
- 13A common C/C++ core specification2 people · 7 points · first shared 2020 · discussion on HN
- 14Type-Safe Parametric Polymorphism2 people · 6 points · first shared 2021 · discussion on HN
- 15Defer Available in GCC and Clang2 people · 4 points · first shared 2026 · discussion on HN
What HN people wrote when they linked it
sigsev_251 · 2023-08-28
You don't really have to use a pointer in modern C. The recommended practice is to use variably modified types these days[1].
[1]: https://gustedt.wordpress.com/2014/09/08/dont-use-fake-matrices/
mananaysiempre · 2022-08-24
As Jens Gustedt points out[1], the following intentional unsigned overflow works perfectly for downwards iteration (even when length is 0 or SIZE_MAX), though it looks a bit confusing at first:
for (size_t i = length - 1; i < length; i--) ...
You are also free to start at any other (not necessarily in-bounds) index, just like with ascending iteration.
[1] https://gustedt.wordpress.com/2013/07/15/a-praise-of-size_t-and-other-…
tempodox · 2022-05-13
As for learning C, I like to recommend Modern C:
https://gustedt.wordpress.com/2019/09/18/modern-c-second-edition/
There are also printed versions.
stephen82 · 2021-02-12
I think "defer" is coming [1], along with other goodies that simplified the life of C++ developers, but time will tell.
I really hope they approve the following:
* auto
* constexpr
* lambda function
* __typeof__ used as typeof; it behaves like decltype
It would lead to cleaner code without excessive macro magic; only where would be needed.
[1] https://gustedt.wordpress.com/2020/12/14/a-defer-mechanism-for-c/
aleksei · 2019-01-11
Aside from K&R, you might want to look at the Modern C PDF https://gustedt.wordpress.com/2016/11/25/modern-c-is-now-feature-compl… for an opinionated but sane guide.
Also 21st Century C has been recommended, and it goes into tooling as well.
anilakar · 2017-09-08
Beej's guides are the best way to get started quickly (i.e. in the time frame of a university course). For a more thorough introduction, one should probably read "Advanced Programming in the UNIX Environment" and "UNIX Network Programming", both from Richard Stevens.
Jens Gustedt has also written a rather nice ebook on how to program in modern C: https://gustedt.wordpress.com/2016/11/25/modern-c-is-now-feature-compl…
cremno · 2015-07-26
I recommend reading the notes section and better yet the following blog entry before one decides to use _Generic with less trivial types:
https://gustedt.wordpress.com/2015/05/11/the-controlling-expression-of…
AlbertoGP · 2021-04-23
I’m actually implementing that right now for my own use, as a pre-processor.
There is a much more advanced design and implementation at “A defer mechanism for C” (December 2020): https://gustedt.wordpress.com/2020/12/14/a-defer-mechanism-for-c/
For my own purposes, I think I can live without handling stack unwinding so I continue working on my pre-processor.
Since the pre-processor is not yet finished, there I use a vector¹ of {.pointer, .destructor} where I put objects after initialization, with one macro at the end of each managed scope that calls the destructors for that scope in reverse order, then another macro meant for the function exit points that calls all the destructors in that vector. This has been built many times before by other people of course, it’s just an exercise to see which difficulties arise.
¹ Vector, growable array: I did my own trivial type-generic growable array, with the classic {.capacity, .len, .items}, but again there are many previous implementations. The two I’ve found more interesting are:
- “C Template Library (CTL)”: https://github.com/glouw/ctl
- “Klib: a Generic Library in C”: https://github.com/attractivechaos/klib/
enriquto · 2020-02-08
I follow regularly these people, these are mostly slow-going blogs or websites:
1. Fabrice Bellard: https://bellard.org/ This is not really a blog, but a traditional website with links to the work of its author (who is probably one of the top programmers ever). It updates rarely, but when it does, it is to expose yet another monumental piece of computing work that will blow your universe.
2. Linus Akesson: https://www.linusakesson.net/ He's always onto some funny crazy things: obfuscated programming, underhanded programming, c64 emulation, chiptunes...
3. Uriel l'Étranger: http://cat-v.org/ The only self-described "philosopher of software" that I have ever seen. His website is of course not updated anymore, but you can re-read it many times and always learn something new.
4. Ted Unangst: https://flak.tedunangst.com/ Nice to follow some cool news about openbsd development
5. Andy Chu: http://www.oilshell.org/blog/ Who has embarked in an amazing quest to turn the unix shell into a cleaner tool
6. Jens Gustedt: https://gustedt.wordpress.com/ If you really want to be up to date about the evolution of the C language
mzs · 2025-11-14
For C23 at least: https://gustedt.wordpress.com/2022/12/18/checked-integer-arithmetic-in…
#include <stdckdint.h>
joshkel · 2024-01-21
According to https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2391r0.pdf, it's an "unadopted feature being explored."
There's more information about the proposal at https://gustedt.wordpress.com/2022/01/15/a-defer-feature-using-lambda-…
signa11 · 2021-01-16
couple of weeks (days ?) back there was a post here which described the new defer mechanism (possible source of reference: https://gustedt.wordpress.com/2020/12/14/a-defer-mechanism-for-c/)
this can do that quite easily afaik.
dependenttypes · 2020-09-12
Here is a post from 2014 from someone who is in the C standard committee. https://gustedt.wordpress.com/2014/09/08/dont-use-fake-matrices/
kzrdude · 2019-10-13
Far from obsolete.. more is coming :)
'Add type generic interfaces for string functions to the C library, see N2068' has been mentioned as a possible C2x addition https://gustedt.wordpress.com/2018/11/12/c2x/
hasahmed · 2019-09-18
Cool stuff!
Typo in first paragraph of https://gustedt.wordpress.com/category/c/ (mayor instead of major)
wahern · 2019-04-24
A draft is freely available here: http://icube-icps.unistra.fr/img_auth.php/d/db/ModernC.pdf (via https://gustedt.wordpress.com/2016/11/25/modern-c-is-now-feature-compl…
It's a solid book. If you like it don't hesitate to buy it.
jabl · 2018-11-16
> two's complement
For C2x and C++2x it looks likely that they will drop support for sign-magnitude and ones' complement representations of signed integers, essentially mandating two's complement.
https://gustedt.wordpress.com/2018/11/12/c2x/
https://herbsutter.com/2018/11/13/trip-report-fall-iso-c-standards-mee…
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0907r4.html
comex · 2018-11-13
The aliasing rule isn’t symmetric: you can access objects originally declared as types other than char using char pointers, but you can’t access objects originally declared as char using non-char pointers. (And malloc()ed buffers are neither of the above and have their own rule.) Here’s a blog post explaining it in more detail:
https://gustedt.wordpress.com/2016/08/17/effective-types-and-aliasing/
pawadu · 2016-11-28
The author has also been involved in development of "musl", a modern C11 compliant standard library implementation:
http://www.musl-libc.org
https://gustedt.wordpress.com/2014/10/14/musl-1-1-5-with-full-c11-libr…
dr_win · 2014-05-26
This approach has a minor issue. "break" changes semantics inside the block.
http://gustedt.wordpress.com/2010/08/14/scope-bound-resource-managemen…
http://blog.sam.liddicott.com/2013/04/using-for-as-brace-less-scope.ht…
binarycrusader · 2013-01-28
I wouldn't call it a "need", more like "occasionally desirable". The short version is that it's a convenient method of letting the compiler handle resource management when you have a variable number of values and sufficient stack space. As others pointed out, it's particularly handy for multi-dimensional arrays.
There are also some possible applications here:
http://gustedt.wordpress.com/2011/01/13/vla-as-function-arguments/
In fairness, I've used them only rarely, but those few times I've used them have saved me a bit of grief.
I could easily live without them if required...