15 ms·
Modern C
- netgusto 6y agoThe CC licensed ebook (PDF) is available here: https://gforge.inria.fr/frs/download.php/latestfile/5298/ModernC.pdf https://gforge.inria.fr/frs/download.php/latestfile/5298/Mod...
- thoquz 6y agoCan 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)
- locuscoeruleus 6y agoWhat about Test Driven Development for Embedded C?
- botto 6y agoSo there wouldn't be anything specific for embedded, you can apply the same testing practice as other systems where you ensure you abstract out the functions in such a way that the logic can be tested. The complexity about embedded starts want to incorporate the testing with things like IO, which is more end to end testing rather than TDD.
- dave84 6y agoThat’s the name of a book.
- ravingraven 6y agoAre you refering to this: https://github.com/BoschSensortec/BMP280_driver/blob/master/bmp280.c https://github.com/BoschSensortec/BMP280_driver/blob/master/... ...? Because there is nothing inherently modern about this code, this is how C has been written for decades if not from the very start (I think you will struggle to find patterns in this code that are not covered by KnR). That being said, there are books that cover relatively new developments in the C language and its ecosystem, such as "21st Centry C" by Ben Klemens (but even this book is something like 5-10 years old).
- mytailorisrich 6y agoFor 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 6y agoMISRA 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 6y agoIs this a good resource for someone using it to improve their C skills, and not necessarily writing a lot of C?
- mjburgess 6y agoAfter 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 6y agoHe 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).
- nikki93 6y agoJust skimmed real quick. It actually seems p. good and I would check it out again more deeply. https://floooh.github.io/2018/06/17/handles-vs-pointers.html https://floooh.github.io/2018/06/17/handles-vs-pointers.html (and the other articles there) have some good ideas about organizing well in plain C / niceties from 'modern' C too.
- teddyh 6y agoI also suggest the comp.lang.c Frequently Asked Questions: http://www.c-faq.com/ http://www.c-faq.com/
- bumblebritches5 6y agoJens Gustedt wrote this, he's very involved in ISO WG14, the group that creates the C standard.
- deleted 6y ago[deleted]
- justinator 6y agoAh yes, I’ll file this between Deafeningly Silent and True Myth.
- three_legs 6y agoSorry, can you explain? As someone who's reinvesting time to learn C lately, I'm very curious
- nikki93 6y agoProbably 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 6y agoWho 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 6y agoRefusing 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 6y agoHumor 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.
- esamatti 6y agoSince 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 6y agoThe 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.
- nine_k 6y agoDo people still use the K&R style of declarations? OTOH a microcontroller is an acceptable approximation of a PDP-11, so much of the old approaches are very directly applicable.
- thojest 6y agoThere is also this https://nostarch.com/Effective_C https://nostarch.com/Effective_C
- tylerscott 6y ago+1 for Effective C. Great writing and diagrams.
- rmrfstar 6y ago+1 most important C intro since K&R
- dave84 6y agoIt's definitely not an absolute beginners book though.
- deleted 6y ago[deleted]
- slmjkdbtl 6y agoSince 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 6y agoJust 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
- pjam 6y agoThis, 100%. I've been working on a side project that is essentially rebuilding Redis but in Ruby, only to learn how things work (https://redis.pjam.me/ https://redis.pjam.me/) and the Redis code base is fantastic. As someone with basically no professional C experience, the clarity of the code base makes diving in fairly easy
- w0utert 6y agoTotally 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.
- susam 6y agoI 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.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf https://web.archive.org/web/20181230041359if_/http://www.ope... 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.
- GoblinSlayer 6y agoI have C74 manual. char was ASCII character occupying lower 7 bit of a signed 2's complement 8-bit number, int was signed 2's complement 16-bit number, no unsigned integers.
- boomer_joe 6y agoI wish the WG14 would publish the TeX sources for the latest working draft. None of the pdf-to-html generators work well, and as a result the most up to date version you can conveniently view in your browser is C99.
- swagonomixxx 6y agoI 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 6y agoThe 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.
- gnu 6y agoI 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 6y agoAn explanation of why you didn't like it would be more helpful.
- sumtechguy 6y agoI used k&r as my first C book. You can learn C from it. However it does teach a C that is not really used in the wild. Specifically function definitions and tri-glyphs. Its memory management is kind of hand wavy and it does not stress enough the importance of getting the types right (like the nightmare of printf). Both of which can cause memory issues very quickly. If you start with that book I would recommend one of those others to go along with it. Using C is easy. Getting it right takes time, practice, and a few stubbed toes.
- gnu 6y agoI too learned C from K&R and really loved it. I did not have any other thing to do and there was no internet and no one telling me that C is bad. Nor was I aware of other cool languages. I did not even have a computer at that time, so I wrote most of the exercises on paper. Later my father bought me a 486DX66 and I typed in most of the programs in the book. Those were fun times!
- gnu 6y agoSure, 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.
- mucholove 6y agoIt’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.
- codr7 6y agoThe list would be infinite; and it's a feature, not a bug. You pick up strategies for avoiding problems along the way, to a higher degree than in less flexible languages. Valgrind is your friend, I couldn't imagine writing C without it anymore. Many compilers also ship with verifiers for undefined behavior which has saved me a couple of times.
- flohofwoe 6y agoAlso: enable all warnings the compiler offers and compile the code with different compilers (clang, gcc, MSVC - they all have different warnings), add copious amounts of assert checks, compile and test with the clang sanitizers enabled (address sanitizer, undefined behaviour sanitizer, thread sanitizer), and run the code through static analyzers (e.g. clang static analyzer and the one in Visual Studio), minimize dynamic allocation and pointer use. With all those combined it's quite hard to hit segmentation faults and memory corruption and the source code will generally become "cleaner" and more robust.
- manishsharan 6y agoThis. I wish all C books had more chapters on this.
- saagarjha 6y agoNot all the warnings, as many are not useful. But take -Wall -Wextra and see how that suits you and tweak it if necessary.
- enriquto 6y agoI 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.
- runbsd 6y agoYou could probably have the PDF printed online, there are some services out there that will do it for relatively cheap.
- enriquto 6y agoI guess that printing an individual book with quality binding would be much more expensive than Manning's bundle.
- auggierose 6y agoWhy don't you buy the bundle and throw away the digital versions (facepalm)?
- enriquto 6y agoI have few principles, but I stick to them! EDIT: Besides, one of the electronic versions in the bundle is sold separately for $24. Assuming that the other electronic version has the same price, the print version alone is worth $12. I don't want to pay $48 for something that will be "thrown away".
- auggierose 6y agoYou are surely trolling me now :)
- WoodenChair 6y agoYou can buy the printed book alone on Amazon or almost any other book seller. Manning's thinking is that the eBook costs them nothing to distribute so if you buy the print book, they might as well give you a bonus to make you even more happy by giving you the eBook. Source: I have worked with them.
- mark_l_watson 6y agoFor 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.
- quelsolaar 6y agoshameless self promotion "How I program C" https://youtu.be/443UNeGrFoM https://youtu.be/443UNeGrFoM
- nikki93 6y agoYour stuff is awesome. :)
- aamsuzon 6y agoThe website having css issue. Admin please fix the issue first. It can not arrange
- donedealomg 6y agoIsn't it still bad these days to hate classes?
- donedealomg 6y agoI really liked this book: C Programming: A Modern Approach by K N King Reading posts like this makes me just only write C code and be done with it.
- skavi 6y agoim a big fan of the crow in the corner.
- einpoklum 6y agoCan 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/1111141883?ean=9781491903896 https://www.barnesandnoble.com/w/21st-century-c-ben-klemens/...
- spacechild1 6y agobe careful about 21st Century C: https://www.amazon.com/-/de/gp/customer-reviews/R3IQKSK19FIEI5/ref=cm_cr_arp_d_viewpnt?ie=UTF8&ASIN=B00NYBRH30#R3IQKSK19FIEI5 https://www.amazon.com/-/de/gp/customer-reviews/R3IQKSK19FIE... I agree with the review author. The quoted paragraph about hash tables is shocking!
- begriffs 6y agoThe ##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.