Long time no C
I'm spending some quality time with C again after a solid multi-year detour with Rust and I'm really enjoying myself.
I <3 Rust too, but the compile times were hurting for gamedev even after tuning optimisations (for the dependencies I was using, at least). In other areas I'll continue using Rust in anger for the unbeatable guarantees it provides (it's a superpower, seriously).
Rust as a language has evolved a lot and continues to grow in complexity; something I don't like much about C++ either. In contrast C is a very small language. There are some hairy pointery bits that can be daunting for newcomers, but the simplicity is refreshing. Tooling has gotten much better at pointing out shitty code these days too (more and better warnings, ASAN, scan-build, etc) so despite losing a lot of the guarantees from Rust I'm still able to code with confidence.
Some links that kick-started my interest in C again:
- How I program C (especially influential in terms of style)
- nothings/stb (public domain awesomeness)
- stb_howto.txt (style guide geared toward single header libs)
- floooh/sokol (sokol_gfx is a nice API)
- nuklear (small immediate-mode UI)
- cute headers (more public domain awesomeness)
- Twitch streamers such as tek256 doing C99, go and follow!
These all show me how with careful attention to style it's possible to write robust yet elegant C while avoiding anti-patterns that commonly lead to bugs.
So long story short I built a new C99 gamedev stack on top of SDL2, sokol_gfx, nuklear, and some other amazing single header libraries. Single header libraries remove so much of the pain of managing dependencies in C (single unit .c/.h combos are okay too).
Whenever I'm writing new subsystems or libraries I try to model off of popular existing APIs. This has had the benefit of using already proven APIs and makes it easier to adapt examples and solutions found online (e.g. by borrowing the naming of shader uniforms from Shadertoy or Unity it's a lot easier to port existing shaders to your platform).
As for new pain points? Well, cross-platform building still sucks. I'm a Linux first developer and so far not had a lot of luck with cross compiling for Windows. But I'm finally having success with MSYS2 (with the mingw64 toolchain) and Windows specific Makefiles so there's hope at last.
Maybe I'll post something to test-drive soon, or see you in another 7 years :)