
Modern C - netgusto
https://modernc.gforge.inria.fr/
======
susam
I usually like to keep copies of the C standards drafts with me. In case
anyone is interested, here are the links:

In case, someone is interested here are the various C standards drafts:

* C89/C90: [http://port70.net/~nsz/c/c89/c89-draft.html](http://port70.net/~nsz/c/c89/c89-draft.html)

* C99 (N1256): [http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf)

* C11 (N1570): [http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf)

* C17/C18 (N2176): [https://web.archive.org/web/20181230041359if_/http://www.ope...](https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf)

Also, here is a nice Stack Overflow answer with links to C and C++ standards
documents:

* [https://stackoverflow.com/a/83763/303363](https://stackoverflow.com/a/83763/303363)

This answer usually gets updated as new revisions of the standards appear.

~~~
swagonomixxx
I don't understand, why are the PDF documents specifying the C/C++ standards
being sold for $$$ when I believe I was able to find them on the respective WG
website?

~~~
colejohnson66
The _finalized and approved_ standard costs money, but being an open standard
(meaning anyone can contribute), the drafts are available for all.

As for _why_ the finalized versions cost money when the final draft is
virtually identical all the time? I honestly don’t know.

~~~
XMPPwocky
Might be just good ol' market segmentation - a company with the money to spend
on a spec isn't likely to settle for a draft, but the average random dev
doesn't care much about the differences.

------
slmjkdbtl
Since everyone is recommending other resources, here's some C developers whose
code I enjoy very much (or just really like the software they created with C):

[https://github.com/rxi/](https://github.com/rxi/)

[https://github.com/floooh/](https://github.com/floooh/)

[https://github.com/antirez/](https://github.com/antirez/)

[https://github.com/qwx9/](https://github.com/qwx9/)

[https://github.com/koekeishiya/](https://github.com/koekeishiya/)

[https://github.com/martanne/](https://github.com/martanne/)

[https://github.com/nothings/](https://github.com/nothings/)

[https://github.com/sheredom/](https://github.com/sheredom/)

[https://git.suckless.org/](https://git.suckless.org/)

[http://viznut.fi/](http://viznut.fi/)

plz recommend if you have more! (mostly interested in the graphics/audio
realm)

~~~
giu
Just want to add and let people know that antirez (creator of Redis) writes so
many insightful code comments that you almost always learn something new when
you go through his projects.

He has also written an article on how he writes the code comments [0]; I've
been using Design, Why, and Teacher comments a lot in my last projects and
they have been very helpful, especially if you come back to the project after
a long time or introduce a coworker to the code base.

[0] [http://antirez.com/news/124](http://antirez.com/news/124)

~~~
w0utert
Totally agree, I went through some of the code in his GitHub repo and it’s a
joy to read through, making it clear what everything is for, how and why it
works, which is rare especially for plain C.

I try to comment my code in a similar way, often ending up with up to 30%
comment to code ratio. I know some (many?) people are very dismissive of this
style and reject the idea you have to write any comments where the code is
‘self explanatory’, but I don’t care. It doesn’t take me a lot of extra time
to document the general idea behind a piece of code and it makes my future
life and that of other devs reading the code so much easier it’s easily worth
the effort to write these comments and keep them up to date.

Like I said it’s rare to see OSS code written that way though, I’ve even
thought on multiple occasions that some projects actively strip all code
comments automatically for whatever reason, considering the total absence of
any form of code documentation in them.

~~~
dllthomas
> reject the idea you have to write any comments where the code is ‘self
> explanatory’

I'm one of those, but in your defense I think we need to maintain a very high
bar for "self explanatory".

At the same time, I think it's important to be aware that comments not
immediately adjacent to what they describe are usually not visible in code
review, are often not visible to the person editing the code in question, will
fall out of date without an active process to keep them up to date, and at
that point will do more harm than good.

I'm curious if you have any particular mechanisms for addressing the above?

I'm trying in my current setting by introducing a mechanism for cross-
references (anywhere in the repo, ^^{label} refers to @@{label}) that my CI
setup can recognize and surface during code review. It's provided a bit of
benefit, but it's underused, and it's too soon to have a good sense of long
term impact.

~~~
w0utert
>> _I 'm one of those, but in your defense I think we need to maintain a very
high bar for "self explanatory"._

I put 'self explanatory' in square quotes exactly because of that, at the time
of writing the code many things may seem self explanatory for the person
writing it, but even seemingly simple things can be very confusing for people
who read the code for the first time. But obviously I'm not advocating
comments that simply describe in words what the next line of code does
mechanically, those are useless. But I do like comments that break up the
algorithm in sections that are clearly marked by comments, even if some parts
of those comments may seem trivial ('loop over all objects of type x and
process those with property y', etc). For me the value is in being able to
read the comments first and get an idea of the structure of the code and the
though process behind it, before actually having to interpret the code itself.

>> _At the same time, I think it 's important to be aware that comments not
immediately adjacent to what they describe are usually not visible in code
review [..] I'm curious if you have any particular mechanisms for addressing
the above?_

Not really. In our team we don't really use code review tools for feedback
about algorithms or higher level design of the code, my experience they are
pretty awful for that anyway. We use bitbucket primarily to point out local
improvements and ask questions why sections where added or changed, but for
higher-level discussion we prefer offline tools like whiteboarding, and
rotating people so everyone works on different parts of the codebase.

------
mucholove
It’s been such a joy to learn C.

There’s a very vocal group that tells you not to write in C because it’s
unsafe, immoral and you’ll burn in hell if you do but the fact is...I would
never be able to understand the problem Rust is trying to solve until I’ve
recreated the problems in C. By now I’ve hit a good amount of segmentation
faults.

Would really love to know if there’s a list of all the possible ways to get
one oF these in C.

~~~
rhacker
> There’s a very vocal group that tells you not to write in C because it’s
> unsafe

I get the reasoning to learn it. Just after you do learn it, stop and use
something else. Unless you absolutely have to. I don't think anyone has
attempted to compute the amount of money spent on buffer overflow hacks. But
I'm guessing it's in the 10s to 100s of billions of dollars if you count all
the viruses that took advantage of it in the past in Apache web server or
Windows NT's NTFS (or sharing etc...) codebases. And that applies to C++ too.

And hey, I know that sounds extreme - but there really are situations of
"unless you absolutely have to" but I wouldn't expect anyone to write a brand
new queuing system or database in C or C++ anymore given the alternative
languages available.

~~~
non-entity
For C I mostly agree, but from what I understand there's still a ton of new
C++ being written and even replacing "legacy" alternative languages even if
they provide advantages.

~~~
stjohnswarts
Modern c++ can get you 95% of what rust offers. It's just that the syntax is
hideous, especially templates

------
netgusto
The CC licensed ebook (PDF) is available here:
[https://gforge.inria.fr/frs/download.php/latestfile/5298/Mod...](https://gforge.inria.fr/frs/download.php/latestfile/5298/ModernC.pdf)

------
mark_l_watson
For most of my career since the 1980s, I have been a Common Lisp and Java
developer. However, I did have an eight year stretch of using C++ at SAIC and
later for PacBell, Disney and Nintendo projects.

When I was done with my professional C++ stint, I fell in love with the
simplicity of C. It was like a breath of fresh air. I stopped using C largely
by accident: everyone who paid for my work wanted Common Lisp or Java, and
that lasted until the start of the deep learning craze seven years ago.

I thank the author for making a CC licensed PDF of his book available.

------
thojest
There is also this
[https://nostarch.com/Effective_C](https://nostarch.com/Effective_C)

~~~
rmrfstar
+1 most important C intro since K&R

~~~
dave84
It's definitely not an absolute beginners book though.

------
gnu
I didn't enjoy this book, to be blunt. K&R still holds up as an interesting
read, despite it not being updated to latest ANSI C standards. It is probably
not a good first book.

A few C books I like:

    
    
      * C: A reference manual.
      * C: Interfaces and Implementations.
      * Deep C secrets.
      * C: Traps and Pitfalls.

~~~
norswap
An explanation of why you didn't like it would be more helpful.

~~~
gnu
Sure, but that is meant as a personal thing and not meant as a general
statement. Everyone should evaluate whether the book (any book) works for
their needs.

The main reason is that, it was a very dry read with various rules and syntax
etc and I got bored looking at it quickly. It almost felt like I am reading an
abridged version of the standard itself. The exercises didn't appeal to me
much.

I didn't mean to dis the efforts of the author at all. There is no other book
that covers the modern parts of the standard well. I am not aware of any other
C book that covers the wide chars than this book.

~~~
rtkaratekid
I had the same experience with this book. I set out as an intermediate C
programmer and ended up just bored to tears with things I felt were obvious
and frustrated that questions about “real” C code were not being answered.
Also the exercises were... very involved for just trying to learn potentially
simple points. I ended up giving up on the book for now, maybe I’ll pick it
back up later or I’ll peruse your list.

------
esamatti
Since learning Rust I wanted to learn some C to be better able to consume pure
C libs or embed Rust into C apps.

Along Modern C I found these modern(ish) C books:

\- C Programming: A Modern Approach, 2nd Edition by King

\- 21st Century C by Ben Kelemens

\- Learn C the Hard Way by Zed Shaw

Can anyone recommend some of these for my background?

Besides Rust I've mostly used Webdev languages JS (mostly TypeScript these
days), Python, Ruby, PHP, some Java back in the day.

~~~
Areading314
The best C book is the Kernighan + Ritchie book "The C programming language",
hands down. This is also one of the best books on practical computer science
available today. Other books could help to provide a more modern take on how
to adapt the language to 2020, but the original K+R book is still the best way
to really learn the language.

~~~
satysin
I've been programming in C for twenty years now and K&R has a special place in
my heart however I do not think it is the best book for a beginner to learn C.

If you're coming from COBOL and wanting to learn C (like the target audience
at the time the book was written) ok perhaps it is a good book for you. But if
you're coming from something like Python or Java or JavaScript (or even no
language at all) there are better options such as K N King's A Modern
Approach.

K&R is a _fantastic_ book in its own right and I certainly think once you feel
more comfortable with C it is a superb book to read and more importantly
complete as many of the exercises as you can.

It is that I have seen too many people come from higher level languages or
with no programming knowledge and find K&R frustrating due to its assumption
the reader is already a programmer in some other (1970s) language with a
fundamental understanding of some programming concepts.

~~~
bluetomcat
K&R is a worthy historical artifact on its own, documenting the then
prevailing programming styles and problems of interest, and the overall
cultural vibe of the programming community back then. It just takes you back
to the creative and somewhat unorderly 1970s atmosphere in Bell labs, with its
former hippies now wearing big glasses and colourful sweaters.

~~~
runbsd
Working at Bell Labs in the 70s/80s must have been interesting.

------
thoquz
Can anyone recommend a book on modern C for embedded?

Architecture which it targets doesn't matter.

I want to see what are best practices, such as what is done in the generic
driver's on GitHub by Bosch for their sensors. (Such as the BMP280)

~~~
mytailorisrich
For best practices you're probably better served by looking at standards and
guidelines specific for embedded systems. For example MISRA C. There is also
the JPL C Coding Standards, which are based on MISRA and are freely available.

~~~
ianhowson
MISRA and the JPL standards are required reading if you're doing safety-
critical work.

They tend to warp the structure of your software and prevent usage of many
useful language features.

If you're not doing safety work, the Linux kernel is a great example of 'nice'
modern C.

------
lactobacillis
Is this a good resource for someone using it to improve their C skills, and
not necessarily writing a lot of C?

~~~
mjburgess
After a quick glance over the book: Yes.

I'm not exactly sure why it's "modern" C, but it is an introduction to C via
establishing a somewhat rigorous and complete fundamental understanding of it.

~~~
larschdk
He makes a point of including all the newer features of C, including fixed-
size integers, thread API, restrict qualifiers, and atomics, and dedicate a
very significant part of the book to them. On top of that he gives many best-
practice advice, that you could call "modern", as they are often violated in
20+ year old C code (and often by people who learned C in the 80's, in my
experience).

------
begriffs
The ##C freenode channel's webpage has a great list of books as well:

[http://www.iso-9899.info/wiki/Books](http://www.iso-9899.info/wiki/Books)

I like that it includes books to avoid, and ideas for further topics.

------
enriquto
I love this book in pdf and I would love to buy the printed version.
Unfortunately, these editors "Manning" do not want to sell the print version
only, they sell you a bundle containing the printed book, an some digital
versions: an "ebook", a "livebook" and whatnot. I asked them, and they refuse
to sell me the printed book only.

~~~
bogomipz
They simply offer you a free eBook version with the purchase of every
paperback book. This is true whether you buy the book directly from them or
from a bookstore:

>"Free eBook With Every pBook! If you are an owner of a Manning pBook you can
get a free eBook at any time easily from your account. If you prefer NOT to
have a Manning account no problem, we won't be offended: we will send you a
one-time download link after purchasing the pBook at manning.com. If you did
not buy the pBook from manning.com, you can still get the free eBook in all
available formats by setting up a Manning account, and registering your
copy."[1]

It's also worth noting that you are supporting a a small independent publisher
that's DRM free, as well as supporting independent authors. They also
regularly have sales, often with 50% discounts, often on holidays. I wouldn't
be surprised if there was a sale on Monday.

[1] [https://www.manning.com/ebooks](https://www.manning.com/ebooks)

~~~
enriquto
> It's also worth noting that you are supporting a a small independent
> publisher that's DRM free, as well as supporting independent authors.

OK, I just bought the bundle. If anybody is interested, I can give one (1) of
you, one (1) copy of the ebook for free.

------
einpoklum
Can someone summarize how this book differs from:

* "Non-modern" C books, like K&R ?

* Other Modern-C books, like "21st Century C": [https://www.barnesandnoble.com/w/21st-century-c-ben-klemens/...](https://www.barnesandnoble.com/w/21st-century-c-ben-klemens/1111141883?ean=9781491903896)

~~~
spacechild1
be careful about 21st Century C: [https://www.amazon.com/-/de/gp/customer-
reviews/R3IQKSK19FIE...](https://www.amazon.com/-/de/gp/customer-
reviews/R3IQKSK19FIEI5/ref=cm_cr_arp_d_viewpnt?ie=UTF8&ASIN=B00NYBRH30#R3IQKSK19FIEI5)

I agree with the review author. The quoted paragraph about hash tables is
shocking!

------
quelsolaar
shameless self promotion "How I program C"
[https://youtu.be/443UNeGrFoM](https://youtu.be/443UNeGrFoM)

~~~
nikki93
Your stuff is awesome. :)

------
skavi
im a big fan of the crow in the corner.

------
bumblebritches5
Jens Gustedt wrote this, he's very involved in ISO WG14, the group that
creates the C standard.

------
justinator
Ah yes, I’ll file this between Deafeningly Silent and True Myth.

~~~
three_legs
Sorry, can you explain? As someone who's reinvesting time to learn C lately,
I'm very curious

~~~
nikki93
Probably aboard the "hate on C" hype train. If you are curious, it could make
sense to not let it get in your way, and continue investigating / learning.
There's a lot to be gained from such an exercise.

FWIW if you're looking for practical projects; part III of
[https://craftinginterpreters.com/contents.html](https://craftinginterpreters.com/contents.html)
is in C, and if you're interested in graphics stuff SDL is really fun. It all
runs in the web / browser too with Webassembly.

~~~
justinator
Who knows? Maybe I'm a C greybeard and the culture I worked in was one where
you can laugh at yourself and your work without feeling like everything has to
be so serious all the time.

~~~
teddyh
Refusing to explain in-jokes, _even when explicitly asked_ , is exclusionary
and insular, and leads to low influx of new people, resulting in a slow death
of a community. A culture, if it wants to survive, must _share_ itself freely
to new potential members.

~~~
justinator
Humor doesn't have to be obvious to be good; and a magician doesn't have to
ever give away the secrets of their illusions, no matter how loudly their
audience cries out.

But I'm terribly sorry if you didn't get it. Just a simple play on words. It's
certainly not insular or community destroying - an accusation like that is
simply hyperbolic. Perhaps like most living things, growth only comes when
there's opportunity to being tested and stressed.

