Live data from Hacker News

Brushing up on operating systems and C programming

shubhro.com

61–70 of 89 posts

Re: Brushing up on operating systems and C programming

#61
post #5

Can anyone recommend an intermediate to advanced C book? I feel like most C material I've been exposed to in the past lacks what a modern C project should have when it comes to best practices, code organization, build tools (should I use make for this, cmake, where does autotools fit? what about clang vs gcc?), linters (valgrind?), testing, etc. I recognize that much of this falls outside of C, but all of these tools…

To answer your questions: * Clang vs gcc: doesn't really matter. Clang has slightly better compile times. GCC has really advanced but in some cases still has inferior warning/error messages. Best practice is not to really use GNU c features unless you want to. If you do want to, decide if you want to just use the subset supported by clang or the full shabang from gcc. Beyond that: if you want to support both, test on…

I like your thinking regarding using simpler build tools. I took this to the extreme and now my build tool for personal C/C++ projects is just a file called build.sh/build.bat. That does little more than:

    gcc main.c
main.c #includes any other .c files that are needed (the term for this appears to be a 'unity build'). Compiling this way is /really/ fast, which is why it's okay to use a dumb build script that always recompiles everything.

Re: Brushing up on operating systems and C programming

#62
post #5

Can anyone recommend an intermediate to advanced C book? I feel like most C material I've been exposed to in the past lacks what a modern C project should have when it comes to best practices, code organization, build tools (should I use make for this, cmake, where does autotools fit? what about clang vs gcc?), linters (valgrind?), testing, etc. I recognize that much of this falls outside of C, but all of these tools…

One of the most challenging exercises in any language is to learn how to organize your code and modularize it at a large scale. I recommend reading Postgres's source code. But don't wander aimlessly, set a goal. For example, figure out how an sql select query is parsed and processed, how types are deduced, etc and learn the programming patterns applied as you go through.

I often recommend postgres because it's highly commented, and easy to understand.

Re: Brushing up on operating systems and C programming

#63

I would also recommend reading Computer Systems: A Programmer's Perspective, 3rd Edition.

Indeed! It's my favorite technical book, several of the chapters have information I've yet to find laid out in comparable detail anywhere online.

The book was written for a CS course (15-213) at Carnegie Mellon University, course materials here (supplement, but no replacement for the book): https://www.cs.cmu.edu/~213/

Re: Brushing up on operating systems and C programming

#65
I like this little book, in very small amount of space it teaches you how to build a bare bones OS, from there you can start doing your own experiments which I think is the best way to really learn something:

https://littleosbook.github.io/

It's good to not only know operating systems in general, but also to understand some of the internals of the operating system you are actually using. For Linux, this is good:

https://0xax.gitbooks.io/linux-insides/content/index.html

Re: Brushing up on operating systems and C programming

#66
post #5

Can anyone recommend an intermediate to advanced C book? I feel like most C material I've been exposed to in the past lacks what a modern C project should have when it comes to best practices, code organization, build tools (should I use make for this, cmake, where does autotools fit? what about clang vs gcc?), linters (valgrind?), testing, etc. I recognize that much of this falls outside of C, but all of these tools…

I'm not claiming any C ability myself, but in addition to things which have already been mentioned: the old Steve Summit comp.lang.c C FAQ http://c-faq.com/ was only updated up to 2005 but is still hard to ignore.

For the Linux C interface there's https://nostarch.com/tlpi and http://www.apuebook.com/apue3e.html / http://www.unpbook.com/ , all old to different degrees. http://www.danlj.org/lad/ was great but even the second edition http://www.worldcat.org/title/linux-application-development-... is probably out of date by now. ( https://9p.io/cm/cs/upe/index.html is most certainly out of date, but more than that it's almost an anti-C-interface book by comparison to the C-API-centric view of Unix which has become prevalent since, in some part due to the popularity of K&R... https://www.cs.princeton.edu/~bwk/tpop.webpage/ and http://www.catb.org/esr/writings/taoup/ are in the same "anti-C-book" vein.)

Re: Brushing up on operating systems and C programming

#67

Earlier quoted context omitted.

To answer your questions: * Clang vs gcc: doesn't really matter. Clang has slightly better compile times. GCC has really advanced but in some cases still has inferior warning/error messages. Best practice is not to really use GNU c features unless you want to. If you do want to, decide if you want to just use the subset supported by clang or the full shabang from gcc. Beyond that: if you want to support both, test on…

I like your thinking regarding using simpler build tools. I took this to the extreme and now my build tool for personal C/C++ projects is just a file called build.sh/build.bat. That does little more than: gcc main.c main.c #includes any other .c files that are needed (the term for this appears to be a 'unity build'). Compiling this way is /really/ fast, which is why it's okay to use a dumb build script that always re…

I do exactly the same thing whenever I write C/C++. Genuinely large projects aside, I see no compelling reason to waste your time with build systems. This approach is simple, easy to maintain and lets you get on with writing actual code.

Re: Brushing up on operating systems and C programming

#68
post #23
post #5

Can anyone recommend an intermediate to advanced C book? I feel like most C material I've been exposed to in the past lacks what a modern C project should have when it comes to best practices, code organization, build tools (should I use make for this, cmake, where does autotools fit? what about clang vs gcc?), linters (valgrind?), testing, etc. I recognize that much of this falls outside of C, but all of these tools…

I really enjoyed "Deep C Secrets" as an intermediate C book: Expert C Programming: Deep C Secrets https://www.amazon.com/dp/0131774298/ A little dated, still lots of relevant knowledge though.

What I liked about this book is that it's very upfront about how messed up C is. I read about half of it and it made me never want to write any C ever again.

An especially memorable part for me was how it took 3 pages of language lawyering to explain why this doesn't compile:

    foo(const char **p) { }

    main(int argc, char **argv)
    {
    foo(argv);
    }

Re: Brushing up on operating systems and C programming

#69

Earlier quoted context omitted.

To answer your questions: * Clang vs gcc: doesn't really matter. Clang has slightly better compile times. GCC has really advanced but in some cases still has inferior warning/error messages. Best practice is not to really use GNU c features unless you want to. If you do want to, decide if you want to just use the subset supported by clang or the full shabang from gcc. Beyond that: if you want to support both, test on…

I like your thinking regarding using simpler build tools. I took this to the extreme and now my build tool for personal C/C++ projects is just a file called build.sh/build.bat. That does little more than: gcc main.c main.c #includes any other .c files that are needed (the term for this appears to be a 'unity build'). Compiling this way is /really/ fast, which is why it's okay to use a dumb build script that always re…

Out of curiosity, why did you not choose make to do this?

Re: Brushing up on operating systems and C programming

#70

Earlier quoted context omitted.

I like your thinking regarding using simpler build tools. I took this to the extreme and now my build tool for personal C/C++ projects is just a file called build.sh/build.bat. That does little more than: gcc main.c main.c #includes any other .c files that are needed (the term for this appears to be a 'unity build'). Compiling this way is /really/ fast, which is why it's okay to use a dumb build script that always re…

I do exactly the same thing whenever I write C/C++. Genuinely large projects aside, I see no compelling reason to waste your time with build systems. This approach is simple, easy to maintain and lets you get on with writing actual code.

Out of curiosity, why not use make for something so simple instead of a Shell script?
Post reply on HN