8 ms·
Beej's Guide to C Programming
- jjgreen 4y agoPfft, what a language, it doesn't even have telemetry.
- CamperBob2 4y agoFor a while, you had to go out of your way to add notelemetry.obj to your linker input to keep Microsoft from adding their telemetry to your program. I don't think they do that anymore, but it's awfully hard to be certain.
- simonw 4y agoBeej's guide to network programming is an absolute classic, dating back to at least 2005 (according to the Internet Archive) - very exiting to see them tackle C programming generally now. https://beej.us/guide/bgnet/ https://beej.us/guide/bgnet/
- elromulous 4y agoBeej is often on here and can confirm the actual inception date, but iirc I used it as far back as at least 1999/2000ish
- tesseract2 4y agoIndeed! I remember first seeing it in late 2000 or early 2001, and it wasn't brand new at that time. I used it as a companion to Richard Stevens' classics on TCP/IP.
- pschw 4y agoFrom his bio: > I'd started off with Beej's Guide to Network Programming back in 1995 or so
- beej71 4y agoI don't remember if I said, but I got started learning this stuff from a networking program someone had written to allow you to play DOOM over the modem, IIRC. So thank you to whomever that was!
- moonshinefe 4y agoAnd thank you for writing the networking guide. I found it in my early teens when I was interested in learning programming and wanted to go beyond the basics to do some more interesting stuff. It helped me write some chatroom bots for things like IRC and battle.net in the early 2000s, which fueled the hobby even more and eventually turned it into a very good career. :)
- Accacin 4y agoYeah! Last week I decided I'd like to write a (very) simple HTTP server in C as a learning experiment. The network programming guide was incredibly useful and the code examples gave me a great base to learn from and extend.
- anthomtb 4y agoBeej’s site is a gem. I remember coming across it in 2010 or so, thinking, yeah this stuff is great but what happens when this guy gets kids or a “real job” and the bit rot sets in? Here we are, closing in on 15 years later, and it’s both still-great and up to date.
- version_five 4y agoI was actually just looking for a C book. I already "know" (I use the term loosely) C but have little insight into how to write real code, and any best practices. Will check this out.
- bigdict 4y ago> how to write real code There are many ways, a codebase would be a better resource than a book.
- beej71 4y agoI agree. The Guide doesn't give many real-world examples (there are zillions of those already out in the real world). It's about how to swing a hammer and turn a screwdriver, not how to build a house. That said, I try to make K&R-idiomatic examples when I can. They're just small-scale.
- CamperBob2 4y agoThat's tricky, though. It would be a bad idea to learn C++ from my code, even though it works well enough. And until you're well along the path to guruhood yourself, you won't know if you're reading good code or bad code.
- c-c-c-c-c 4y agoGet a VM running NetBSD or OpenBSD and check out the source code and play with it!
- incanus77 4y agoThe second volume reference is great too, and downloadable as zipped HTML and PDF. https://beej.us/guide/bgclr/ https://beej.us/guide/bgclr/
- beej71 4y agoThis I modeled off The Turbo C Bible, one of my favorite all-time reference books that still sits on my shelf. I thought its killer feature was examples for everything.
- jamal-kumar 4y agoIs there something like a changelog to this? I remember years ago people on freenode #C pointing out tons of mistakes in this [1] and trashing it as a reference to learn from but it seems like it's gone through a decent amount of revision at this point. [1] https://www.iso-9899.info/wiki/Main_Page#Stuff_that_should_be_avoided https://www.iso-9899.info/wiki/Main_Page#Stuff_that_should_b...
- RicardoLuis0 4y agoit seems to be on github, but the commit history doesn't go beyond 2017: https://github.com/beejjorgensen/bgc https://github.com/beejjorgensen/bgc
- beej71 4y agoYeah, any history before git is lost aside from what you might find on archive.org. And I started writing it ages ago, then shelved in it a half-done state. And then it got that probably well-deserved review. But its former self is barely recognizable since it has been heavily rewritten and expanded over the past 3 years, so I hope the iso-9899.info folks give me a regrade at some point in the future.
- jamal-kumar 4y agoCool to hear from you as the author, thanks for the reference! I'm now pretty curious to check out your network programming guide.
- thrwawy74 4y agoNot to be pander, but I wonder if anyone has worked on a translation of this to Rust.
- doodlesdev 4y agoTell me you use Hacker News without telling me you use it hahahaha. But seriously, I'm not sure of any kind of material like this for Rust, but I believe that's because it's simply not needed since we already have "the book" [0], rustlings [1], and rust by example [2]. Honestly, learning Rust is just absurdly simple and straightforward if you have the motivation to do so, these guides are so good I don't see much of a good reason to develop different ones. [0]: https://doc.rust-lang.org/book/ https://doc.rust-lang.org/book/ [1]: https://github.com/rust-lang/rustlings/ https://github.com/rust-lang/rustlings/ [2]: https://doc.rust-lang.org/stable/rust-by-example/ https://doc.rust-lang.org/stable/rust-by-example/
- steveklabnik 4y agoAs someone who helped write one of those guides… I would encourage people to write even more. Different texts can help different people. The more the merrier!
- thrwawy74 4y agoThis is exactly what I have found. You can find 10+ guides on networking and usually it's 1 chapter from this author, 1 from this author, 2 from over here... the perspectives or writing styles collage together to present me with the thing that helps the material "click". Enough exposure and you become capable :)
- beej71 4y agoI just want to go on record as saying there will never be a *comprehensive* Beej's Guide to Rust. There will never be another comprehensive Beej's Guide to Any Language, for that matter. I've learned my lesson. :) C is one of the most simple languages there is, and it's YOUGE. There's a good reason other books skim over the library functions. The only saving grace is that C is relatively mature and (hopefully) doesn't change much every decade. Rust is changing so quickly it'd be a near-full-time job just to keep up. Maybe I'll write some blog posts about Rust sometime as I improve with it. I think the language is all kinds of fun. And the free Rust books and tutorials that are out there are already awesome.
- teknopaul 4y agoRe: "You can declare a function static if you only want it visible in a single source file." Static means different things in different languages, and in C in different places. In what sense is a static C function static/unmoveable? or a static / class variable static in Java? I find a lot of programming language guides tell you what without a coherent why.
- david2ndaccount 4y agoIt’s static as it will always resolve to the same function. An extern function depends on whatever you link against (or users link against if you provide a static library).
- beej71 4y agoHi gang! I know there are some incorrectitudes in there around the inline part of the guide... but if you find others, I'd really appreciate emails or GitHub issues or PRs. The goal is to have a comprehensive, free, zero ads or tracking, up-to-date guide to C that fits between cppreference and other higher-level books. Target audience is college students who suddenly have to learn C for their OS or Networking course. :) I also haven't put any C23 stuff in there yet, but that's on deck. I have until December, right? ;)
- BruceEel 4y agowhile you're here, I'm seizing this opportunity to thank you for that wchar_t section, it really is good work. As for C23, quality takes time :)
- beej71 4y agoThat was the second-hardest part to write (behind atomics). Glad to hear it's useful, for sure. I envy modern languages that were able to simple shrug their shoulders of decades of history and declare "UTF-8 everywhere!"
- ninepoints 4y agoEven those languages have to contend with win32 utf16 conventions anyways I suppose
- vasco 4y agoThanks a lot for your networking materials. 10 years ago it got me through a hard networking course in university and it showed me how good teaching materials could be. I'm not programming C professionally but your stuff made me a better programmer.
- fisf 4y agoJust wanted to throw out a thank you. Your guide was one of the first 'serious' programming material I was exposed to, close to 20 years ago. Let's just say it was immensely helpful, and I might not be where I am now, without it.
- fsociety 4y agoI started my career solely as a C dev and got pretty good at it. This is by far the most useful resource whenever I have to dip my toes back into it.
- waynesonfire 4y agois there something like this for Common LISP?
- dang 4y agoRelated: Beej’s Guide to C Programming [pdf] - https://news.ycombinator.com/item?id=26911399 https://news.ycombinator.com/item?id=26911399 - April 2021 (171 comments) Beej's Guide to C Programming - https://news.ycombinator.com/item?id=26100391 https://news.ycombinator.com/item?id=26100391 - Feb 2021 (1 comment) Beej's Guide to C Programming (2007) - https://news.ycombinator.com/item?id=15198093 https://news.ycombinator.com/item?id=15198093 - Sept 2017 (79 comments) Beej's Guide to C Programming - https://news.ycombinator.com/item?id=8295024 https://news.ycombinator.com/item?id=8295024 - Sept 2014 (1 comment)
- ratherlongname 4y agoYour guide to network programming got me through a difficult course in my Bachelors! Thank You!
- tialaramex 4y ago> it is connected to the bare metal in a way that present-day languages are not. While obviously C is closer to the metal than say, Python, it's far less clear that this is true for a language like Rust† and I am increasingly dubious about the value of any of these high level languages (yes, even C) to learn "How the machine really works". I reckon it's probably more instructive to write a little bit of ARM assembly than to learn enough C to get to the same place today. † Trivial example: Your CPU arithmetic operations probably natively behave exactly the way Rust's Wrapping<u32> Wrapping<i64> etc. types do. In C the unsigned integer types, once you figure out how big yours are, are similar, but the signed ones are not!
- swatcoder 4y agoThe key difference to me is where you use “probably”. Rust and even WASM reflect a lot of the system behavior that’s become the norm among modern hardware platforms. But those norms are still not universal and it’s useful to maintain an understanding of other viable architectures. C was born from a time of of extremely high innovation and experimentation in hardware architecture and it’s baked many of those possibilities into its language. Often, those are the very footguns that can make writing commercial software in C something to be considered carefully, especially because performant and safer alternatives like Rust exist. Yet, using C is still sometimes the right choices for commercial software and remains a unique instrument for privately expanding one’s understanding of system and hardware architecture. The quoted claim about C doesn’t have to be wrong just to argue that Rust might often be a better choice in practice for commercial bare metal programming on common systems. It’s making a subtly different claim, and the difference can matter.
- leourbina 4y agoJust wanted to say thank you. your content was crucial in getting me to understand network programming and was crucial for my masters thesis. Your content has always been crisp, to the point and accesible. Keep it up!
- blonky 4y agoBeej is a great guy. He was my instructor at this boot camp I attended. I learned a little C from him. I can’t really do much with it, but it was fun to learn.
- cwdegidio 4y agoI just have to say thanks to beej71 for making this guide. I'm doing my Masters in CS right now (I'm predominately a web developer... js, java, etc) and only used C++ one time in my undergrad. Your guide was my go to resource when doing things like an echo server/client and implementing a barebones http protocol. Can't thank you enough.
- radicalriddler 4y agoWoah! I saw this on HN a while back, but forgot to bookmark it and lost it. I recognized the name instantly, glad to find it again, and will make sure to save for a weekend where I hate myself sufficiently to dive into this massive document!