15 ms·
Ask HN: Best book to learn C in 2022?
I know a few other languages but have really been wanting to learn C. I see a lot of books all with a lot of praise and it's difficult choosing one.
Any recommendations?
- orsenthil 4y agoUsing K&R, I try to practice the problems and understand them to learn C. I use my project https://www.learntosolveit.com/ https://www.learntosolveit.com/ to do that.
- cyrc 4y agoHave a look at Modern C for Absolute Beginners by Slobodan Dmitrović https://link.springer.com/book/10.1007/978-1-4842-6643-4 https://link.springer.com/book/10.1007/978-1-4842-6643-4
- baydonFlyer 4y agoAs someone who teaches C to professional engineers, I'd recommend "Hacking: The Art of Exploration" by Jon Erickson. The first 100+ pages are the most succinct coverage of C I've ever come across (if you can already program in other languages). Also, by following many of the exploits covered in the book, you get a real grasp of what is happening at the machine level - which is one of the major reasons you'd choose C over something more modern.
- gregjor 4y agoK & R
- coffeeblack 4y agoJust got this one a few days ago, liking it so far.
- stjohnswarts 4y agoI hear those guys know a lot about C.
- pjmlp 4y agoYet most ignore lint, created by those guys for good C programming practices.
- lloydatkinson 4y agoI don’t imagine OP had a 34 year old book in mind when there has been multiple C standards since then.
- anthk 4y agoFrom ANSI C to C99 there isn't many changes. Just read K&R C 2nd ed and then the book on Modern C which can be understood in a literal afternoon after doing the K&R one.
- marginalia_nu 4y agoK&R is still the gold standard, not just for C books but technical writing in general.
- icedchai 4y agoThose standards barely change anything. You could discuss the “new features” over the last 30 years in about 10 pages after learning the fundamentals. (10 pages may be high.)
- gregjor 4y agoSome of the best programming books date from that era. Programming hasn’t really changed all that much in decades. New tools and languages, sure. Mostly retreads or derivatives.
- flohofwoe 4y agoThe problem with K&R is that it stops at C89, while C99 almost feels like a new and much "friendlier" language (mainly because of compound literals and designated initialization). (e.g. shameless plug: https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.html https://floooh.github.io/2019/09/27/modern-c-for-cpp-peeps.h...) K&R 2nd Edition is still a very good read of course, but mainly for all the little interesting details that are not directly related to the C syntax, but there really should have been a K&R 3rd Edition when C99 came around.
- gregjor 4y agoK&R remains one of the best books about learning C, and learning programming. There’s more to learning C, or any language, than learning the syntax.
- aintmeit 4y ago
- iExploder 4y agoI suggest OP rewrites their post in Rust.
- nix23 4y agoI suggest you first rewrite a operatingsystem in rust, maybe ask the openbsd community.
- ducktective 4y agohe was being ironic...
- nix23 4y agoI was a bit too in suggesting asking OpenBSD dev's :)
- anthk 4y agoThe C programming language, 2nd edition. Then if you are into BSD/Posix, Advanced Programming Unix environment. Here's a course on C programming for Unix, NetBSD actually. You can install NetBSD with ease. If not, head to sdf.org and try getting an user account. You can validate a basic account for cheap. But if you help the rest of the community with programming under Unix, you may get a validated account for free. Do the Unix programming that after TCPL 2nd Ed, BTW. https://stevens.netmeister.org/631/ https://stevens.netmeister.org/631/
- dev_0 4y ago
- equilibrium 4y agoC Programming: A Modern Approach by King Edit: I just saw your post history - if you don't mind me asking what approach/resources did you take with self-teaching yourself?
- throwaway2037 4y agoI needed to re-learn C programming for a mid-career change. This book was a life saver. I will never forget how details the explaination was about printf. That book is incredibly thorough.
- CodeSgt 4y agoWell for self-teaching Python and JS/TS/html/CSS I mainly just followed YouTube videos with a healthy dose of side projects. For learning Elixir I bought "Elixir in Action" and then supplemented with my own side projects.
- miguendes 4y ago+1. King’s is amazing, IMO. Very didactic and covers C in depth.
- stusmall 4y agoThis is my favorite of the bunch. I remember picking it up as a long time C dev hoping to learn a new, modern approaches. It helped hammer home that you can only modernize a 50 year old language so much. I didn't come away with from it with a lot of new tricks or techniques. It's just a dated language that has a very specific time and place and when using it, you have to deal with its age.
- randcraw 4y agoK&R 1e, 236 pages K&R 2e, 272 pages King, 832 pages
- Egoist 4y agohttps://gustedt.gitlabpages.inria.fr/modern-c/ https://gustedt.gitlabpages.inria.fr/modern-c/
- JonChesterfield 4y agoIf you must learn C, which is probably sensible even if you never code in it, this ^ is the one to go for. I liked "deep C secrets" by Peter van der Linden some years ago.
- SAI_Peregrinus 4y agoI second shis. It's an excellent book.
- adipginting 4y agoA ~1/10 part of this book will test your C skill, not quite an introductory book. https://wordsandbuttons.online/SYTYKC.pdf https://wordsandbuttons.online/SYTYKC.pdf
- jll29 4y agoOver the years, I have acquired most of what people call seminal C books, and after reading them, I recommend the following two books to people who already know programming: Peter A. Darnell and Philip E. Margolis C - A Software Engineering Approach (3rd ed.) https://www.amazon.com/Software-Engineering-Approach-Peter-Darnell/dp/0387946756 https://www.amazon.com/Software-Engineering-Approach-Peter-D... David Hanson C Interfaces and Implementations: Techniques for Creating Reusable Software (!st ed.) https://www.amazon.com/Interfaces-Implementations-Techniques-Creating-Reusable/dp/0201498413 https://www.amazon.com/Interfaces-Implementations-Techniques... The first is clearly written and focuses on ANSI C (lexis, syntax and semantics), with a healthy dose of software engineering education along the way, which you may already have. (It does not yet cover the latest ISO changes.) The second book is a true gem that teaches even seasoned programmers how to implement correct, clean and portable components as libraries in ISO C, with plenty of source code to show how the true masters of the language craft the finest code you can in C. Most books how fragments of linked list implementations, but only this book shows complete a whole range of important ADTs you cannot live without (e.g. List, Ring, Atom) in C portably, with strong typing, bullet-proof error handling etc. (Hanson is also the author of lcc, a portable C compiler.) I'm actually surprised that these are both are so little known, and that the second one hasn't seen more editions.
- mhd 4y agoOne can only learn a language one time, so I've got a hard time recommending first books. But I definitely second the recommendation for the second book here ;) Hanson's style is a bit idiosyncratic, with his somewhat Modula-3-ish naming style and literate programming use, but there are a lot of usable data structures in there, and I especially like that the focus is on the module level, not on the algorithms themselves. Now, having said that, if you're in a particularly weird sub-domain of C, books from there might supersede or at least color a lot of what you're doing on a day to day basis. In the days of yore, if you wanted to do Win16/Win32 programming, getting to work with your Petzold early is a good idea, and I would assume the same to be true if you do glib/gobject based Gtk programming. Two free resources that looked good to me and that I forwarded in the past were "An Introduction to the C Programming Language and Software Design"[1] by Tim Baily and "Beej's Guide to C Programming"[2]. Those are a bit more concise than your average intro to C book, but for some paths (prior experience, quick headway to C++ etc), they might be sufficient. [1]: https://www-personal.acfr.usyd.edu.au/tbailey/ctext/ctext.pdf https://www-personal.acfr.usyd.edu.au/tbailey/ctext/ctext.pd... [2]: https://beej.us/guide/bgc/ https://beej.us/guide/bgc/
- armitron 4y agoKing is good, also Seacord’s books: Effective C and Secure Coding .. Just ignore suggestions (parroting really) for K&R. It’s probably the worst introduction to C when it comes to good habits, undefined behavior and writing secure code, since it doesn’t even attempt to cover any of these but presents a total facade regarding what programming in C is like. K&R has created generations of people who call themselves C programmers but are essentially clueless when it comes to deep understanding of the language. Anyone that recommends K&R today is someone you want to avoid taking any advice on programming from.
- mburee 4y agoWell when K&R C was released the compiler landscape did look very different. I'm sure back then you could get away with a lot more UB than nowadays, where LLVM and GCC will use every millimetre of leeway you give them to break your programs.
- frou_dh 4y agoThe memetic nature of the term "K&R" also seems to have resulted in a lot of people who think Kernighan created Unix, and don't know who Ken Thompson is.
- flohofwoe 4y agoK&R was a very interesting read for me, but not actually for the description of the C language, but because it describes why certain features in C look the way they do, and because it is also surprisingly and refreshingly critical towards the language (e.g. it basically admits that the function pointer syntax was a mistake). It also corrected my oversimplified view that C is a simple and small language simply because it is an old language, but it was already a simple and small language compared to other languages in the late 60's and early 70's 'programming language zoo'. All the code examples are deeply rooted in the 80's programmer mindset though, and are not very relevant for "modern C".
- cxr 4y agoIt's hard to take someone seriously or believe that they've even read the material when they say stuff like this. K&R (2nd ed.) is constantly calling out undefined behavior, etc. and gives you information you need to start out on a path to be a real stickler about the language. I spent time on my own learning C from K&R since the CS program at my school didn't expose anyone to C (or C++) during the first year. Later, in e.g. the computer architecture course or the data structures course when C was being used liberally (and sloppily), and as I was running across lots of C in the wild, I was continually frustrated by the frequency I saw people relying on common-but-undefined behavior that's explicitly identified as unsafe/unreliable in K&R. Here's my advice to the original poster: If you come across unsubstantiated comments telling you to ignore K&R for all the bad things it contains, then ignore those. Or you can ask for evidence of the bad things they say about it. It's become a meme in the last few years to write meatless swipes about how bad K&R is, but in all the times I've asked for evidence of the things it's purportedly rife with, no one has ever produced anything. The most egregious thing I know of is that it uses `gets` and `puts` in some places—while taking extra effort to tell you it's wrong to use them. This is arguably exactly how do-not-do-this wisdom should be imparted. There is one criticism that holds true about K&R, if you're being generous (to the naysayers, that is), which is that it really does just teach you C the programming language (with some extra stuff about the UNIX system interface at the end). It's not a general software engineering book. You don't learn about build tools or how to structure large, maintainable programs. It exposes you to the fact that C has various nooks and crannies, and it teaches you them, and that's all it really tries to be.
- wanderlust123 4y agoAny resources that take a project based approach to teaching C? I find just learning language features in isolation doesn’t give a complete picture.
- AlexeyBrin 4y agoSecond part of "Crafting Interpreters" shows how to write a bytecode interpreter in C. But the book assumes you know some C.
- meatjuice 4y ago
- dzogchen 4y agoGood luck using Rust for PostgreSQL development, or 100.000 other projects that use C. Not everything is a greenfield project.
- gl-prod 4y agoMy goodness, what an idea. Why didn't I think of that? https://www.youtube.com/watch?v=BOEYSLlQy9s https://www.youtube.com/watch?v=BOEYSLlQy9s
- wakeupcall 4y agoLearning more programming languages will make you a better programmer irregardless as it will expose you to different programming patterns, paradigms and the limitations/improvements that result from those. This is especially true for a popular language, no matter if the language is considered "good" or not. This allows you to understand the libraries/code you will encounter down the road. I would only discourage one from learning a programming language which is tied to a specific commercial product (most of those just die in the same niche and thus lack the practical utility).
- CodeSgt 4y agoAs a matter of fact, that's part of the reason I want to learn C. I started learning Rust, and see a lot of potential, but ultimately find I lack the context to: 1. Appreciate the language. 2. Really understand what's happening in memory. I hope that learning C will provide both of these things, while also gaining the benefit of learning one of the only widely used languages that I can fit in my head all at once.
- deleted 4y ago[deleted]
- wmwragg 4y agoDespite what many think, I'd say the "The C Programming Language (2nd Edition - ANSI C)" by Brian Kernighan & Dennis Ritchie (K&R) book is still a good introduction to C. It doesn't go into best practices, or other forms of more advanced C programming, but it teaches C well. I'd pair it with "Understanding and Using C Pointers: Core Techniques for Memory Management" by Richard M Reese to get a good understanding of the pointer underpinnings of C. They are both small, well written and easily digestible.
- tchaffee 4y ago> K&R I've read a lot of books about programming over the many decades I've been doing this, and the K&R book still stands out as one of the best examples of how to do a good job of documenting the tool you've just built. The K&R book gave me the heuristic of "read the book by the folks who wrote the language". That heuristic turned out to be mostly wrong. But the book has stood the test of time.
- thesnowdog 4y agoI read The Awk Programming Language shortly after K&R and came away with the idea that I should consider reading whatever Kernighan (co)wrote. I don't think I got further than The Practice of Programming but that was three winners in a row...
- tylerscott 4y agoI second this. I would include The Go Programming Language as well. I will buy any book the Kernighan has had a hand in writing.
- talkingtab 4y agoIf you are starting with C I second this. C is a really good language to learn because it is not as far from what a cpu does. You end up understanding more of the workings. When someone says "garbage collection" you understand. In my opinion understanding an assembly language and C are fundamental to programming.
- 4y ago
- Trex_Egg 4y agoI recommend "Computer Systems: A Programmer's Perspective", as it also give a good explanation about how a computer works under the hoods.
- xaduha 4y agoFollow up question should probably be what is a good IDE setup for plain C. CGO support in VSCode for instance never really worked for me. How well does C/C++ plugin by Microsoft work on linux?
- flohofwoe 4y agoI'd recommend starting in VSCode with the MS C/C++ plugin (this works across Windows, Linux and macOS) and do the very first steps without a build system (the VSCode C/C++ plugin has some support for building single-file projects). Or just build in the terminal with: cc hello.c -o hello After those first steps I would recommend installing the MS CMake Tools extensions (https://github.com/microsoft/vscode-cmake-tools/blob/main/docs/README.md https://github.com/microsoft/vscode-cmake-tools/blob/main/do...), this automatically discovers CMakeLists.txt files in the project and then uses those to setup build- and debugging targets and configure the C/C++ language server / Intellisense. I prefer this setup because it is more 'transparent' than a 'fat IDE' like Visual Studio, Xcode or CLion, but YMMV of course :)
- CodeSgt 4y agoI plan to use CLion
- bitwize 4y agoYour first C program should be written in an editor like vi, and compiled with cc at the command line. Use tools like IDEs when you're ready for more sophisticated programs and really need their help to manage the complexity. If your only exposure to C is through an IDE, the IDE can hide important things you really should know (that's kind of its job). I knew a girl in college who was really smart and on a CS major track. At the time everybody used Borland C++, and some people's first exposure to C++ -- or programming in general -- was through this IDE. She asked me if her C++ classroom exercises would compile on a laptop. I said it should be fine. Then she said, "But isn't there like a chip or something in my desktop that compiles the programs?" I was a bit flabbergasted that anyone would think that, but simply replied that the compiler was just another piece of software that will run on any PC. People come in to programming and they don't understand what's going on. A lot of details are hidden with development today. And it's great that we have the IDEs and so forth to help us not be bogged down in these details -- but a greater perspective is useful to any programmer, and that's why I and Charles Petzold and some other programmers recommend that your first, simple programs be done "the old fashioned way". (Come to think of it though, maybe if there were a compilation chip -- an FPGA or something -- the compilation times of C++ and Rust could be mitigated...)
- tmtvl 4y agoI personally quite like James Aspnes' Notes on Data Structures and Programming Techniques, it teaches you enough C to be dangerous and proceeds on a whirlwind tour through most of the data structures you'll encounter in the wild. You can find it here: https://cs.yale.edu/homes/aspnes/classes/223/notes.html https://cs.yale.edu/homes/aspnes/classes/223/notes.html
- pajko 4y agohttps://en.cppreference.com/w/c https://en.cppreference.com/w/c
- tunnuz 4y agoI’m not endorsing this as I haven’t read it, but perhaps someone can say if it’s any good for the purpose of learning C from scratch https://www.oreilly.com/library/view/21st-century-c/9781491904428/ https://www.oreilly.com/library/view/21st-century-c/97814919...
- armitron 4y agoIt's terrible, the bad reviews on Amazon are accurate.
- raddan 4y agoI am surprised to see nobody mention Practical C Programming (https://www.amazon.com/Practical-Programming-Does-Nutshell-Handbooks/dp/1565923065 https://www.amazon.com/Practical-Programming-Does-Nutshell-H...) by Steve Oualline. Before I studied computer science in school, I read this book and successfully taught myself C. Readers here may consider it to be a bit remedial, but if you’re struggling to understand the other recommended books, start here. I attempted to read K&R half a dozen times back then, unsuccessfully. Looking back at it now, I can see why: K&R’s examples are hard for true beginners to wrap their minds around. I now teach C as a part of an upper level undergraduate course; the key to understanding most of C’s counterintuitive behavior is to have a clear understanding of its relationship with memory. In fact, I quite like C. It is simple and elegant in many ways. It is also just super unsafe.
- jmercan 4y agoI would say "Effective C" is a good book (and Robert is awesome) but personally I feel like I learned the most by writing and disassembling small quines under different compilers and flags more than anything else. Also, reading through some codebases gave me good (and horrible) ideas and habits. However, C projects are usually messy and I am not sure whether recommending it would be helpful or just confusing. But I would say TenDRA, BearSSL, pkgconf, s6, kivaloo, apk-tools, libsodium, musl, OpenSSH and cosmopolitan libc are worth checking out. Finally increasing my tiny understanding of architectures, memory models and decades of safety issues was significantly helpful as well.
- hiepph 4y agoNot a book. But this is a good notes/roadmap/etc. https://www.cs.yale.edu/homes/aspnes/classes/223/notes.html https://www.cs.yale.edu/homes/aspnes/classes/223/notes.html K&R is a bit more intermediate. Come back to it when you're more experienced.
- rubyskills 4y agoI really enjoyed "Learn C The Hard Way" by Zed Shaw. His style of learning resonates with me. https://learncodethehardway.org/c/ https://learncodethehardway.org/c/
- muunbo 4y agoSecond this! Hilarious book but also very practical
- sureglymop 4y agoIf you have ADHD like me I would recommend "Head First C" from o reilly. Was very visual and covered a lot. Then I continued with The C Programming Language. Sadly I haven't found something similar for rust yet.
- UnpossibleJim 4y agoit's the dirty little secret in my programming library but these have small, digestible chunks that I can read or do in 5 to 10 minutes at a time and then walk away and do something else (or do more, if my brain is firing right that day). I never used to need to study this way when I was younger, but things change now that I'm older and I've adapted =)
- bjourne 4y agoRichard Stallman's free C book is pretty good: https://www.cyberciti.biz/files/GNU-C-Language-Manual/GNU%20C%20Language%20Manual.pdf https://www.cyberciti.biz/files/GNU-C-Language-Manual/GNU%20...
- bl4ck_goku 4y agoLooks unfinished and not formatted properly.
- davisr 4y agoBecause they linked you to a poor version. The manual is very high-quality. Here's a good version. http://www.davisr.me/dropbox/rms-c-20221008/c.pdf http://www.davisr.me/dropbox/rms-c-20221008/c.pdf Source in Savannah. https://savannah.gnu.org/git/?group=c-intro-and-ref https://savannah.gnu.org/git/?group=c-intro-and-ref
- bl4ck_goku 4y agoCool!
- mm007emko 4y agoAs other mentioned, The C Programming Language (2nd Edition - ANSI C)" by Brian Kernighan & Dennis Ritchie (K&R). I learnt from this book. It's still good for the basics.
- maskull 4y agoI'm a C++ programmer that's not done anything directly in C. I stumbled by this book Fluent C By Christopher Preschern just published this month and I thought the organization looked rather interesting. It covers many programming concerns and details several patterns for dealing with them. One thing that's neat is it often refers to open source projects where the pattern is applied so one could go take a more detailed look.
- fhchl 4y agoI recommend "Modern C" by Jens Gusted. https://www.manning.com/books/modern-c https://www.manning.com/books/modern-c The C language can be quite tricky to navigate (at least to me) and this book helped me a lot to understand writing idiomatic code.
- taxcoder 4y agoAgreed. The tool chain help in here is very useful for a beginner.
- pjmlp 4y agoRegarding K&R C, you should read it for its historical relevance to the C programming language, that is about it, it isn't 1980 any longer. Secure C from Oreilly and Modern C from Manning are more relevant in 2022. Then have a look into Frama-C and SAL security frameworks, MISRA C, and CERT C coding standards.
- gizlu 4y agoHm, C language (itself) hasn't got much major changes since ANSI standardization. I would say that one is able to grasp changes relevant to him, by whipping through the changelog for 10-15 minutes Edit: If you are critizing K&R for not teaching how to write safest code then, well, you are right. It is simply not meant to do that
- pjmlp 4y agoCompare C23 with K&R C. You're right on the security part, and that C authors hardly care about it is visible on the language itself, naturally the book wouldn't be any better.
- xwowsersx 4y agoSince this seems to come up a lot (hence, Steve's blog post), I'll link to "C is not how the computer works" https://steveklabnik.com/writing/c-is-not-how-the-computer-works-can-lead-to-inefficient-code https://steveklabnik.com/writing/c-is-not-how-the-computer-w... Note: neither I nor Steve are discouraging anyone from learning C. I'm learning it myself, but some caveats are in order.
- makz 4y agoIf you don’t mind, I’d like to ask you why you want lo learn C. I’m asking because I’d like to improve my C but I can’t decide between that and learning Rust.
- rramadass 4y agohttps://old.reddit.com/r/ProgrammerHumor/comments/5ur106/to_my_friends_who_are_just_learning_c/ddwg4s3/ https://old.reddit.com/r/ProgrammerHumor/comments/5ur106/to_...
- RunSet 4y agoOP: "How can I do x?" Top reply: "Why do you want to do x?" Thought I was on StackOverflow for a second.
- CodeSgt 4y agoWell I don't think they were asking in an adversarial way like you might find on SO. Seems as if they just wanted some insight into my decision making process and why I chose to do x over y so they can better make the decision themselves.
- CodeSgt 4y agoWhy not both? Being able to better understand and appreciate Rust is one of a couple factors motivating me to learn C. The others being gaining historical context when analyzing modern c-based languages, being able to effectively read from some of the greatest codebases in the world, and the desire to learn a language that's small enough to fit inside my head and can run anywhere.
- ccouzens 4y agoI've read but not written any c since learning rust. I've written some c years ago. I do feel that if I were to write more c now it would be better for me knowing rust and having a feel for designs that pass the borrow checker. Unhelpfully the only c book I've read was the k&r book. It seemed fine. Perhaps the question would be easier to answer if the reason for wanting to learn c was given (eg to contribute to existing c based project or to write embedded code)
- photochemsyn 4y ago"C in a Nutshell 2nd Ed" (O'Reilly, Prinz & Craqford, 2015) is a good reference although maybe not the best for a walk-through learning experience. It also has good chapters on tooling (gcc, make, gdb). There's a recent book out I came across called "Bare Metal C" (No Starch Press, Oualline, 2022) which unpacks embedded programming in a very readable manner. I imagine a lot of, if not most, C programming these days is done in the low-level embedded world, and this book clears up a lot of the mysteries. https://nostarch.com/bare-metal-c https://nostarch.com/bare-metal-c Also it never hurts to look at a good open-source codebase written in C, for example the SQLite code is worth looking at (if a bit overwhelming): https://github.com/sqlite/sqlite/tree/master/src https://github.com/sqlite/sqlite/tree/master/src
- synergy20 4y ago"Extreme C: Taking you to the limit in Concurrency, OOP, and the most advanced capabilities of C" at https://www.amazon.com/Extreme-Taking-Concurrency-advanced-capabilities/dp/1789343623 https://www.amazon.com/Extreme-Taking-Concurrency-advanced-c.... Especially if you want to do OOP in C instead of playing with C++.
- khnov 4y ago
- mwcampbell 4y agoPlease don't do this. The Rust community has a bad enough reputation for over-aggressive evangelism as it is. We should try to fix that.
- gkuan 4y agoBesides K&R and Modern C, I like the classic Expert C Programming: Deep C Secrets by van der Linden.
- Blackstrat 4y agoI agree on K&R and Expert C. I preferred Seacord’s Effective C to Modern C.
- maldev 4y agoLearn C by hand and just writing toy programs. Then read Cert C to learn coding patterns. C requires unique coding patterns compared to other languages, most relating to safety or language features.
- readme 4y agoI read K&R 20 years ago and today it's still the closest programming book to my heart -- yeah there's more modern choices but the exercises are unmatched, it's short, and it's one of the most fun books you'll ever read. The standards for C99, C11 are open. Look up what you don't learn in them and grab one of the other more modern suggestions from here for that, but K&R is a must have for any C programmer. You probably won't be able to put the book down if you start reading it.
- squarefoot 4y agoTechnical aspects aside, K&R has what some modern books seem to lack: a really clear and comprehensive layout. I've picked up a few modern books and immediately noticed how they make use of thinner (thinner != smaller) fonts that make then hard to distinguish. At first I thought it was my fault for being old and wearing glasses, but as soon as I opened back some other old books like the K&R, the Niklaus Wirth (Algorithms+Data Structures = programs) and a couple other ones, I could read again without effort at the same distance wearing the same pair of glasses. Why do they use fonts that thin today?
- chromatin 4y agoAs some other posters do, I recommend "Modern C" by Jens Gusted. You can read it for free here: https://gustedt.gitlabpages.inria.fr/modern-c/ https://gustedt.gitlabpages.inria.fr/modern-c/ And if you like it, I encourage you to purchase a copy here: https://www.manning.com/books/modern-c https://www.manning.com/books/modern-c
- xwowsersx 4y agoThe "Downloads" link there returns a 404
- juunpp 4y agohttps://hal.inria.fr/hal-02383654 https://hal.inria.fr/hal-02383654
- xwowsersx 4y agoThanks!
- xwowsersx 4y agoDo you know what's with the ␣ (open box, U+2423) character in his first example? printf("element␣%zu␣is␣%g,␣\tits␣square␣is␣%g\n" I have a feeling the PDF file is messed up...Or is he showing you a literal space?
- teh_klev 4y agoHe's using that to represent a space character. I guess it forces you to pay more attention to the examples rather than copy-pasting.
- tialaramex 4y agoThis representation for the space U+0020 was very common historically, because a space doesn't look like anything at all, especially if sometimes it's important whether there is no space, one space or two spaces, explicitly showing each space can help. It seems very rare these days.
- hankchinaski 4y agoThe first time I was interested in programming I started learning C. I was 14 and what I used was "The C Programming Language" book. It was a great experience,
- kazinator 4y ago> I know a few other languages Just skip the tutes and books, and read drafts of the ISO C standard. C99 is the most widely used. For newcomers, C11 might make sense. Here: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf Absorb that and then you can play the Game of Spot The Error in C books and tutorials. Not to mention git repos of C programs.
- _osorin_ 4y agoI would like to take it a step further and ask a question that has been bothering me a while. On my time in the academy I studied the following two books (regarding C): [1] Advanced Programming in the UNIX Environment https://www.amazon.com/Advanced-Programming-UNIX-Environment-3rd/dp/0321637739 https://www.amazon.com/Advanced-Programming-UNIX-Environment... [2] C Programming Language https://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628 https://www.amazon.com/Programming-Language-2nd-Brian-Kernig... In combination with other classes (and books) on networking, operation systems, data structures we covered a big variance of use cases with C. My question is: How do I take this to the next level? For example I feel I never missed a concept from those classes but when I see C code posted on a thread here it's probably something completely unreadable and complex. Can anyone provide resources to advance a little? What should I study if my goal is to make good and useful modern C software? I feel like my typing is a bit abstract but I will be happy to clarify. PS Yes, I've heard of C++ and Rust ;P
- belter 4y agoStart by reading Redis code, slowly take notes on paper, try to make your version changing small bits at a time. https://github.com/redis/redis/tree/unstable/src https://github.com/redis/redis/tree/unstable/src Entry point here at line 6816: https://github.com/redis/redis/blob/unstable/src/server.c https://github.com/redis/redis/blob/unstable/src/server.c Also "Code Reading" will be useful. - https://www.amazon.com/Code-Reading-Open-Source-Perspective/dp/0201799405 https://www.amazon.com/Code-Reading-Open-Source-Perspective/... "Code Reading" tends to be criticized, but I think mostly unfairly.
- _osorin_ 4y agoThanks a lot for the recommendation.
- zh3 4y ago[1] is a very good book - it's not really one for learning C though, it's more for when you know C and you need to use it in - well - an advanced unix environment. Sort of like you shouldn't be learning how to use a scalpel in an operating theatre :)
- jalino23 4y agothese comments are gem itself
- bmitc 4y agoI highly recommend Head First C. Don’t be taken aback by its appearance. It’s an excellent book that drives the concepts home.
- ttanev 4y agoI am reading that, and I like it too so far.
- gte525u 4y agoC the complete reference - it's part tutorial, part reference, part project book. At the end, there is project where it walks you though making a mini-c interpreter. That project is very approachable and to be honest - that alone is worth the price of the book.
- cryptonector 4y agoThe best one might be https://doc.rust-lang.org/book/ https://doc.rust-lang.org/book/
- ljosifov 4y agoMentioned by most, still another vote for K&R "The C Programming Language" - for the sheer joy of it! It still puts a smile on my face recalling how much fun it made learning C. :-) Don't think I've read as measured and not-boring for another language since. Close to as much fun to read was maybe Steve Maguire's "Writing Solid Code". Not strictly about learning C, but the examples are all in C. (some people dislike it's K&R not ANSI C)
- n8henrie 4y agoNot to derail the OP too much, but I've also been C-curious for a while, but specifically for writing wrappers C++ projects (for FFI calls from rust, swift, etc.). I've written a few such wrappers that work, but I have no idea what I'm doing WRT const void * et al. and would love to understand it a little better. Are there any of these resources that would help me understand how to write better FFI code in C, while maybe skimping on details that are less important if I don't plan to write much code that is "C first"? Thanks for any suggestions. Apologies in advance for wrong terminology and generally being a noob.
- rramadass 4y agoYour question is not clear; are you trying to call into C++ libraries from Rust/Swift using their FFI to C? Something like this? Rust/Swift -> <FFI> - > C -> C++ libraries If so, you first need to understand ABIs and the C ABI in particular. Start here - https://stackoverflow.com/questions/2171177/what-is-an-application-binary-interface-abi https://stackoverflow.com/questions/2171177/what-is-an-appli... Providing a C interface to C++ is done using "extern C" - https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-c?noredirect=1&lq=1 https://stackoverflow.com/questions/1041866/what-is-the-effe... So you should now have a binary C++ library but which exposes its public interfaces using C language conventions and linkage i.e. C ABI. You can now call into the above using your Rust/Swift FFI. I am not familiar with these so you will have to look at their FFI docs. Here is one for Swift - https://stackoverflow.com/questions/24004732/how-to-call-c-from-swift https://stackoverflow.com/questions/24004732/how-to-call-c-f... Be very careful about strictly following the rules for FFI since you are bridging two different languages with their own semantics and runtimes which could be very different from each other. See - https://en.wikipedia.org/wiki/Foreign_function_interface https://en.wikipedia.org/wiki/Foreign_function_interface The key is to understand what a ABI is and how the C ABI has become sort of de-facto standard for FFIs.
- n8henrie 4y agoThanks for your response! I would edit to clarify but missed the edit window on my post. > are you trying to call into C++ libraries from Rust/Swift using their FFI to C? Yes. Examples (just POC, getting things to link and compile): <https://github.com/n8henrie/brokencppmap https://github.com/n8henrie/brokencppmap> <https://github.com/n8henrie/swiftcpp https://github.com/n8henrie/swiftcpp> Thanks for the links -- I've been putting things together here and there from a combination of SO and the Rust user forum, which is why I was wondering about a more formal reference focused on this use case.
- _gkvv 4y ago[dead]