
Learn C Programming with Open-Source Books - vinny12
https://www.ossblog.org/learn-c-programming-with-9-excellent-open-source-books/
======
agentultra
One of the greatest non-free books, IMO, is _21st Century C_ and I cannot
recommend it enough.

[http://shop.oreilly.com/product/0636920033677.do](http://shop.oreilly.com/product/0636920033677.do)

~~~
a3n
Working my way through it now, in my efforts to re-learn C. Besides the
treatment of modern standard C, I like that it treats the C development and
distribution environment as a first class subject.

------
akarambir
One thing I always not see people recommending is what small open source
projects I can study or do while or after reading these books. Like for web
development, people try to implement a small todo, blogging software. For
someone coming from higher level languages like Python, Ruby, studying low
level library is very tough to grasp. Having small but a proper project in
itself will be helpful. I have heard praises about Redis and SQLite, but for
beginners, they are quite big.

So any suggestions?

~~~
dhruvrrp
A personal preference of mine is to write a simple http server with GET and a
few error codes implemented. It usually covers networking, file IO, exceptions
in some cases, multi-threading, string parsing, etc. If it feels like too much
then you can always start off with a smaller subset of features.

~~~
ejanus
Threads? That is not for beginners.However, your idea is great last summer I
was told to code such in an interview that with a hook to Lisp. I learnt so
much even though I failed the interview.

------
bluetomcat
Great applauses for not recommending the "indisputable classic" from K&R. The
latter is really an introductory text that presents the features of the
language in a chaotic manner and introduces some very nasty 1970s styles of
coding.

~~~
sigjuice
Is there a list of this very nasty 1970s styles of coding somewhere? Is it
mainly that it is outdated and doesn't describe the lastest C standards?

~~~
bluetomcat
It is bad not only because it predates C99, but also because virtually any
example consists of a couple of global variables/fixed-size arrays, a couple
of badly named functions which operate on the globals and use some very
"descriptive" names of the local variables. This book was born in an era when
the modern understanding of "good code" was barely honored at all.

~~~
gtz62
"Relying too heavily on external variables is fraught with peril since it
leads to programs whose data connections are not at all obvious" \- k&r, ch. 1

Who are these Kernighan and Ritchie guys? They obviously just don't understand
"good code", terrible book!

~~~
bluetomcat
Take, for example, the declaration parsing example and honestly tell me that
this isn't crappy code by any modern standard:

    
    
        enum { NAME, PARENS, BRACKETS };
        void dcl(void);
        void dirdcl(void);
        int gettoken(void);
        int tokentype;
        char token[MAXTOKEN];
        char name[MAXTOKEN];
        char datatype[MAXTOKEN]; /* data type = char, int, etc. */
        char out[1000];
    
        main()  /* convert declaration to words */
        {
            while (gettoken() != EOF) {   /* 1st token on line */
                strcpy(datatype, token);  /* is the datatype */
                out[0] = '\0';
                dcl();       /* parse rest of line */
                if (tokentype != '\n')
                    printf("syntax error\n");
                printf("%s: %s %s\n", name, out, datatype);
            }
            return 0; 
        }

~~~
eltoozero
Pg 124 from 2nd edition where this code is pulled (emphasis mine):

" _[T]he programs are intended to be illustrative_ , not bullet-proof, there
are significant restrictions on dcl."

In context this code illustrates the points they're trying to convey about
complicated declarations quite well and is a precursor to understanding
typedef later in the book.

Also, you left the nice inline comments off the variable declaration block.

~~~
ejanus
I would like to see where typedef could have been used?

------
splesjaz
Another great one ; [http://icube-
icps.unistra.fr/img_with.php/d/db/ModernC.pdf](http://icube-
icps.unistra.fr/img_with.php/d/db/ModernC.pdf)

~~~
aktau
Scrolling randomly through the document my eyes almost popped when I saw
[Level 3, Chapter 16: Performance]:

    
    
      A pointer to a collection of objects of unknown number. These functions
      should use the VLA notation:
     
          void func(size_t n, double a[n]);
    

I had no idea this was possible. Do compilers actually do anything with this
information or is it just informative?

 _EDIT_ : I didn't get a warning out of gcc

    
    
      #include <stddef.h>
     
      int last(size_t n, int a[n]) {
        return a[n-1];
      }
     
      int main() {
        int a[] = {0, 1, 2, 3, 4};
        size_t siz = sizeof(a) / sizeof(a[0]);
        return last(siz+1, a);
      }
    

Compile:

    
    
      $ cc --version
      cc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
      Copyright (C) 2013 Free Software Foundation, Inc.
      This is free software; see the source for copying conditions.  There is NO
      warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
      $ cc -Wall -Wextra -std=c11 staticarr.c -o staticarr && ./staticarr ; echo $?
      254
    

clang 3.8 warns about differing things:

    
    
      $ clang-3.8 -Weverything -std=c11 staticarr.c -o staticarr && ./staticarr ; echo $?
      staticarr.c:3:25: warning: variable length array used [-Wvla]
      int last(size_t n, int a[n]) {
                              ^
      staticarr.c:3:5: warning: no previous prototype for function 'last' [-Wmissing-prototypes]
      int last(size_t n, int a[n]) {
          ^
      2 warnings generated.
    

Still, it's a neat idea from a documentation point of view, and GNU-like
compilers seem to accept it.

A bit before is more explanation of on the arr[static ?] notation. I was aware
of this and usually prefer to use (Clang/GCC) function annotations to indicate
NULL-ness of pointers and such, but I see the advantage in some situations. I
don't agree with everything in the document, but it contains a lot of cool
things.

~~~
kps
VLAs were added in C99, but not universally adopted (particularly by embedded
systems compilers, for obvious reasons), and then made optional in C11.

~~~
pantalaimon
I don't see an obvious reason - that's all information that's available on
compile-time, there should be no additional run-time cost - or what are you
implying?

~~~
gcp
VLA allows for run-time size determination, not compile time

------
Scarbutt
The [http://c-faq.com/](http://c-faq.com/) is a very good resource too.

------
andrewclunn
Not a story that interests me, but this is a wonderful blog! I'm definitely
following this.

~~~
aninteger
Maybe I am not seeing the same articles as you.

\- 5 best open source board games to play online.

\- 9 ASCII games you'll want to play again.

\- 3 open source python shells.

So basically just a blog that creates lists. We see this a bit too often on
YouTube. I am not sure we need more boingboing/BuzzFeed style of blog spam..

------
kensai
All gems!

------
pwnna
Are there some recommended book on

