10 ms·
Beej's Guide to C Programming (2007)
- yorwba 9y agoBeej's Guide to Network programming (http://beej.us/guide/bgnet/ http://beej.us/guide/bgnet/) is also pretty good. It was effectively used as the textbook in my networking class. (There was also an actual textbook, but almost nobody bothered to read it.)
- saagarjha 9y agoSecond this guide. It’s pretty short, but it has everything I’ve seemed to need at least.
- nurettin 9y agoThis has been around for 15+ years. I wouldn't be surprised if it is recommended to every newcomer on forums and chat channels.
- da02 9y agoWas there anything in the textbook that was explained better than in the Beej Guide?
- TallGuyShort 9y agoI would wager the textbook probably covered history & development, various topologies, congestion control algorithms, queueing theory, etc. There is more to networking than programming sockets. But for a guide on programming sockets, which is all it sought to do, yeah it's excellent.
- TorKlingberg 9y agoIt's definitely worth reading, but be aware that it's quite old-fashioned in that it focuses entirely on blocking I/O and select(). Also this page fails to explain why you would call shutdown(): http://beej.us/guide/bgnet/output/html/multipage/shutdownman.html http://beej.us/guide/bgnet/output/html/multipage/shutdownman...
- da02 9y agoThanks for pointing this out.
- nix0n 9y agoWhat has replaced select()?
- elromulous 9y agoepoll on linux. Other apis on other oses. More reading: http://www.kegel.com/c10k.html http://www.kegel.com/c10k.html
- fish_fan 9y agoKqueue on the bsds and darwin.
- jandrese 9y agoAlthough there is a case for still using select(). If you're looking at avoiding porting headaches and aren't dealing with a large number of descriptors then select() still works fine. The alternatives are mostly necessary when you're dealing with large numbers of connections (thousands), which most people aren't. Of course there's also the slight problem that select()'s interface with the file descriptor packing macros and the unusual requirement to figure out which file descriptor is the largest numerically that might push people to the alternatives. That is also a valid reason IMHO.
- dgoodell 9y agoDo you perhaps have some examples of some more modern resources or examples we can consult? I would appreciate it.
- anilakar 9y agoBeej's guides are the best way to get started quickly (i.e. in the time frame of a university course). For a more thorough introduction, one should probably read "Advanced Programming in the UNIX Environment" and "UNIX Network Programming", both from Richard Stevens. Jens Gustedt has also written a rather nice ebook on how to program in modern C: https://gustedt.wordpress.com/2016/11/25/modern-c-is-now-feature-complete/ https://gustedt.wordpress.com/2016/11/25/modern-c-is-now-fea...
- agumonkey 9y agoI've seen this suggested in many reddit or other websites threads. Also in college classes yes. Used it to implement ICMP echo heh.
- noxToken 9y agoI will also share praise for Beej. My network programming course was in C, and most of my programming experience had been in Java, Python, and JavaScript. This guide was probably the reason I passed.
- alexanderbisc 9y agoThis is amazing. It's a shirt and a quick understanding guide.
- robotresearcher 9y agoThat's a unusual combo.
- nathell 9y agoI like the style. It's somewhat reminiscent of _why's Poignant Guide to Ruby. (I wouldn't be surprised if the inspiration were actually in the reverse direction.)
- da02 9y agoAlso good as a supplement: * A Tutorial on Pointers and Arrays in C: http://home.netcom.com/%7Etjensen/ptr/pointers.htm http://home.netcom.com/%7Etjensen/ptr/pointers.htm * Right-left Rule: http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html http://ieng9.ucsd.edu/~cs30x/rt_lt.rule.html (via HN) * More free C stuff: https://github.com/EbookFoundation/free-programming-books/blob/master/free-programming-books.md#c https://github.com/EbookFoundation/free-programming-books/bl... (I had to go search through lots of stuff to finally find resources that explain things in a way that I can understand. Once it is explained to me in a certain way, C code suddenly feels a lot less cryptic and I feel a lot less hopeless/useless.)
- kuharich 9y agoPrior discussion: http://news.ycombinator.com/item?id=5241220 http://news.ycombinator.com/item?id=5241220
- nikbackm 9y agoThat's for network programming.
- nippples 9y agoBeeJ's guides don't get as much visibility as they deserve.
- deleted 9y ago[deleted]
- omginternets 9y agoBeeJ's guides to other things: http://beej.us/guide/ http://beej.us/guide/
- gre 9y agoHe even wrote a League of Legends guide. Beej's Guide to Lane Control and the Early Game http://forums.na.leagueoflegends.com/board/showthread.php?t=149979 http://forums.na.leagueoflegends.com/board/showthread.php?t=...
- unwind 9y agoVery good. A pet peeve is that it consistently says "sizeof()", like this: You can use the sizeof() operator to determine how many bytes of memory a certain type uses. (I know, sizeof() looks more like a function than an operator, but there we are.) BUT: sizeof does not in fact need the parentheses always! Syntactically they are part of the argument, and only needed when the argument is a type name, i.e. the argument looks like a cast to that type. So: int x; printf("%zu == %zu\n", sizeof x, sizeof (int)); It's very annoying to see the guide kind of glance off the way things really are, into confusion. Very glad to see it doesn't cast the return value of malloc(), too. :)
- geekodour 9y agoAbout casting the malloc() : http://c-faq.com/malloc/mallocnocast.html http://c-faq.com/malloc/mallocnocast.html
- unwind 9y agoYeah, that's a good resource. I also recommend https://stackoverflow.com/questions/605845/do-i-cast-the-result-of-malloc https://stackoverflow.com/questions/605845/do-i-cast-the-res....
- slavik81 9y agoSimply referring to it as the 'sizeof operator' would be preferable. Otherwise ignoring the ability to drop the parentheses seems fine though. That way the author presents a simple, useful conceptual model and hints that it's actually a little more complicated than they described. Seems like a good trade-off, as there's lots of stuff to learn, and sizeof's hidden weirdness is unlikely to bite any students. When writing code, there's basically no drawbacks to just following the simpler rule of always using parentheses and it makes expressions a little easier to follow [1]. [1]: https://lkml.org/lkml/2012/7/11/103 https://lkml.org/lkml/2012/7/11/103
- kzisme 9y agoAs someone who currently works with C# - is there much of a point to learning C? I've always found it interesting, but never had a reason to jump into it.
- Koshkin 9y agoWhile C remains the single most important programming languages of all time, its share of popularity is shrinking, giving way to C++, C#, Java, and Swift (from Objective-C). Nevertheless, I don't think anyone should call themselves a (true) programmer unless they know C. C is easy to learn, because it's a small language. If you are not new to programming, pretty much all there is to know is in the second edition of the K&R book.
- kzisme 9y agoI've been using C# on a daily basis for ~2 years at this point. I've had that book on my wish list for awhile, but wasn't sure if I would make use of it - I'll likely order it soon.
- sn9 9y agoK&R is a great book and should be read by everyone both for culture and as a model of technical writing. After working through the problems, two books that would be great followups are Hanson's C Interfaces and Implementations and Bryant and O'Hallaron's Computer Systems: A Programmer's Perspective.
- ZenoArrow 9y ago> "Nevertheless, I don't think anyone should call themselves a (true) programmer unless they know C." You could make an even stronger claim about knowing an assembly language. The point being that understanding how a computing device works is helpful in getting the best out of it. If that wasn't your point, then C is no more special than any other popular programming language. Also, whilst I only know the basics of C, it's pretty clear things have moved on considerably since the days of K&R. It doesn't cover any of the enhancements included in C99 and C11, nor does it cover the tooling and coding conventions (the ones that help avoid problems) that have become commonplace since 1989. For a more up-to-date reference, I've heard good things about 21st Century C: http://shop.oreilly.com/product/0636920033677.do http://shop.oreilly.com/product/0636920033677.do
- ausjke 9y agoBeej wrote one of the best programming content online and I hope he can update some of them(C11,posix IPC, epoll/poll,etc).
- davidw 9y agoWell that's cool - digging around a bit, I found out that he runs a hacker group right here in Bend: http://bend.hackersguild.us/#page-main http://bend.hackersguild.us/#page-main
- kumarvvr 9y agoAre there any good tutorials for cross platform development with C++ on windows. I just want to avoid MSVC compilers and use clang or gcc. Also, C++ module/package/library management is very very confusing. You have to configure multiple files in multiple folders and multiple configuration entries. I tried it almost a dozen times and just left it out of frustration. Compared to development with python, it's just mind numbing.
- AlexeyBrin 9y agoYou can install Msys2 http://www.msys2.org/ http://www.msys2.org/ and use GCC 7. Your compiled code will be 100% native Windows executable and will run on other Windows machines.
- webaholic 9y agoYou can now use clang as an alternative compiler in Visual Studio. Other option is to install bash on windows and install gcc/clang and use that.
- jcelerier 9y ago> Are there any good tutorials for cross platform development with C++ on windows. Install QtCreator with MinGW. Here you can just compile your code and have it work. > You have to configure multiple files in multiple folders and multiple configuration entries. not on sane systems where you just do `apt-get install libsdl1.2-dev` or `pacman -S gtk` or `brew install qt boost`
- bigtunacan 9y agoI hear QtCreator mentioned on Hacker News quite frequently. A couple of questions, if you don't mind. 1) How well does it work if you are trying to stick to C and not go the C++ route? 2) They are GPL licensed, so not very permissive, or quite expensive for a commercial license. Is there a significant difference in feature set between the open source & commercial versions for someone that just wants to take it for a spin?
- 9y ago
- ateesdalejr 9y agoYup. This guy is great. Downloaded this a while ago for offline reading while I'm on the go.
- oseph 9y agoThis is wonderful. I see that this guide is sort of "old news" to many of the experienced programmers hanging out here. But as someone who isn't that experienced and about to begin a course on Data Structures + Algorithms using C, this is amazing. Thank you.
- cosinetau 9y ago> I see that this guide is sort of "old news" to many of the experienced programmers hanging out here. https://xkcd.com/1053/ https://xkcd.com/1053/ Carpe diem.
- sn9 9y agoThese two sites were invaluable for me when I was in your position: http://iso-9899.info/wiki/Main_Page http://iso-9899.info/wiki/Main_Page and http://c-faq.com/ http://c-faq.com/
- bap 9y agoBeej was a couple years ahead of me at Chico - he was an awesome guy then and it looks like he's been keeping at it ever since.
- chaoticmass 9y agoI remember using Beej's guide to learn how to do TCP/IP stuff in C around ten years ago. Very well written and easy to follow. http://beej.us/guide/bgnet/ http://beej.us/guide/bgnet/
- throwaway7645 9y agoThe first listed program to add up all the integers from 1 to the scanned number wouldn't compile under GCC for me and the error was that "i" undeclared (first use in this function). I had to declare "i" as an "int" to make it work. It looks like it accepted the declaration in the top with num and result or within the for loop.