Ask HN: How do I learn C properly?
I am in the same boat as you are...bare with me by no means I am an expert.<p>In fact, I read couple of chapters in Modern C yesterday :). Here are some of
the things I am doing to improve my C skills to match with some of the
admired&#x2F;professional developers.<p>Decide which platform to use<p>~~~~~~~~~~~~~~~~~~<p>Unfortunately, to become proficient in it we need to write code and focus on a
platform. I have been fighting between whether to develop on Windows vs Linux. I
am very experienced in Windows environment(using debuggers&#x2F;cl&#x2F;linkers&#x2F;Windbg
etc) but when it comes to writing good quality C code(not C++) and for learning
how to write good maintainable moderately large source code, my research showed
that Windows compilers&#x2F;C standard APIs are not great, in fact they hinder your
productivity. I have wasted countless number of hours to just figure out how to
properly create a simple C project with a decent build system. Unfortunately, I
could not find one. The closest I could find is CMake as MSBuild is a nightmare
to work with. I even tried NMAKE but failed. When it comes to documentation of
finding basic C Api usage,
MSDN(<a href="https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;cpp&#x2F;c-runtime-library&#x2F;run-time-routines-by-category" rel="nofollow">https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;cpp&#x2F;c-runtime-library&#x2F;run-t...</a>)
does a decent job. But in the name of security you will find zillion
variations(<i>_s, </i>_l) of an API and by default msvc compiler will not let you use
some of the API in their simple forms. Instead, you have to define
_CRT_SECURE_NO_WARNINGS etc. I think for someone just getting started to
develop&#x2F;learn to write a decent code base in C these restrictions really
hinder the productivity. So finally, I have decided to instead focus my learning
on Linux platform(currently through WSL - Windows subsystem for Linux) with its
POSIX apis. You know what, `man 3 printf` or `man 3 strlen` is soooooo much
better than googling msdn<p>Mastering C<p>~~~~~~~<p>I think, the simple and straight answer here is reading good code and writing
&quot;good&quot; code and also reading good C content(be it books or articles). I think
these are the three ingredients necessary to get started. Of all the open source
projects that I have investigated, I found Linux Kernel and related projects
seems to have very good taste in terms of code quality. Currently, I am just
focused how they use the language rather than what they actually do in the
project. Things like, how they structure the project, how they name things, how
they use types, how they create structures, how they pass structures to
function, how they use light weight object based constructs, how they handle
errors in function(for example forward only goto exits), how they use
signed&#x2F;unsigned variables etc(more of my learnings to the end), how they use
their own data structures. I think its good to initially focus&#x2F;target on ANSI C
API with C99 instead of heavily relying on the OS specific API on which ever
platform you choose. For example, such projects could be writing binary file
parsers for example projects like .ISO file format etc.<p>Good C projects&#x2F;articles<p>~~~~~~~~~~~~~~~<p>1. Winlib.net - <a href="https:&#x2F;&#x2F;github.com&#x2F;jcpowermac&#x2F;wimlib" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;jcpowermac&#x2F;wimlib</a> is a great source of information<p>2. e2fsprogs - <a href="https:&#x2F;&#x2F;git.kernel.org&#x2F;pub&#x2F;scm&#x2F;fs&#x2F;ext2&#x2F;e2fsprogs.git&#x2F;" rel="nofollow">https:&#x2F;&#x2F;git.kernel.org&#x2F;pub&#x2F;scm&#x2F;fs&#x2F;ext2&#x2F;e2fsprogs.git&#x2F;</a><p>3. MUSL - <a href="https:&#x2F;&#x2F;git.musl-libc.org&#x2F;cgit&#x2F;musl&#x2F;tree&#x2F;" rel="nofollow">https:&#x2F;&#x2F;git.musl-libc.org&#x2F;cgit&#x2F;musl&#x2F;tree&#x2F;</a><p>4. General C Coding Style - <a href="https:&#x2F;&#x2F;git.kernel.org&#x2F;pub&#x2F;scm&#x2F;linux&#x2F;kernel&#x2F;git&#x2F;torvalds&#x2F;linux.git&#x2F;tree&#x2F;Documentation&#x2F;process&#x2F;coding-style.rst" rel="nofollow">https:&#x2F;&#x2F;git.kernel.org&#x2F;pub&#x2F;scm&#x2F;linux&#x2F;kernel&#x2F;git&#x2F;torvalds&#x2F;lin...</a><p>4. <a href="https:&#x2F;&#x2F;nullprogram.com&#x2F;tags&#x2F;c&#x2F;" rel="nofollow">https:&#x2F;&#x2F;nullprogram.com&#x2F;tags&#x2F;c&#x2F;</a> - great source of C knowledge<p>5. CCAN - <a href="https:&#x2F;&#x2F;github.com&#x2F;rustyrussell&#x2F;ccan&#x2F;tree&#x2F;master&#x2F;ccan" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;rustyrussell&#x2F;ccan&#x2F;tree&#x2F;master&#x2F;ccan</a> - great source of C tidbits from none other than Rusty Russell - I haven&#x27;t read all of them<p>6. POSIX 2018 standard - <a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799.2018edition&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799.2018edition...</a><p>continued in the comment....