r/C_Programming • • Feb 23 '24

Latest working draft N3220

134 Upvotes

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf

Update y'all's bookmarks if you're still referring to N3096!

C23 is done, and there are no more public drafts: it will only be available for purchase. However, although this is teeeeechnically therefore a draft of whatever the next Standard C2Y ends up being, this "draft" contains no changes from C23 except to remove the 2023 branding and add a bullet at the beginning about all the C2Y content that ... doesn't exist yet.

Since over 500 edits (some small, many large, some quite sweeping) were applied to C23 after the final draft N3096 was released, this is in practice as close as you will get to a free edition of C23.

So this one is the number for the community to remember, and the de-facto successor to old beloved N1570.

Happy coding! 💜


r/C_Programming • • 12h ago

Learning C weekly megapost for 2026-12-02

7 Upvotes

If you have questions about how to learn C:

  • which books are best?
  • which videos are best?
  • which classes are best?
  • which websites are best?
  • is there a "roadmap"?
  • what projects can I do?

then this is the thread for you. Add your question here. Do not make a stand-alone post, as it will be removed.

Remember that our sub has a very useful wiki that has a great list of resources for learning C programming.


r/C_Programming • • 13h ago

Flat structures VS nested structures?

18 Upvotes

Hello!
I have this deep conflict that has been with me for months now. How is it better, flat structures or nested structures? Or what do you prefer?

Flat example :
struct entity = {
int x = 20;
int y = 40;
string texture = "mario.png";
int current_health = 100;
int current_armor = 100;
}

Nested example :
struct position = {
int x = 20;
int y = 40;
}
struct stats = {
int current_health = 100;
int current_armor = 100;
}

struct renderable = {
string texture = "mario.png"
}
struct entity = {
position position;
stats stats;
texture texture;
}

I have tried to use nested structures as often as possible because that's the norm but they are becoming a pain in my experience. Mostly, it comes down to boilerplate, the risk of getting paths wrong when there's too much nesting and theoretical purity where I find that a property would've worked better in another component.

But with flat structures? I get much better results, more directness, easier debugging and less cognitive load as a property is defined in only one way, even if the names get longer or repetitive. Also, that's how computers like to think and as a CS engineer, I learned how computers think before learning how humans program so I lean towards more old school polling / procedural algorithms.

If I were to make an analogy of how that makes me feel, it would be like owning a big tools box. When I open the box, I can instantly see and pick or place the drill, the screwdriver, the screws and whatever else is there. But with nesting... if feels like after opening the tools box, that the drill has it's own mini-box, that the screws are in another box and so on. I prefer seeing the whole picture at once instead of always having to deal with involvement at micro-scales of a big thing.

Also, I noticed that older games like Doom are closer to flat structs. The thing is, my game isn't very complex in terms of gameplay and it features multiplayer matchmaking. And it's on the server side where I noticed that a flat structure would be much easier for debugging, serialisation and overall faster development speeds.


r/C_Programming • • 23h ago Bravo

Article Zero-initialisation shenanigans

Thumbnail napcakes.nekoweb.org
45 Upvotes

r/C_Programming • • 16h ago

Question Need help avoiding circular dependency

5 Upvotes

[Solved but I'll gladly accept new solutions]

I am making a small clone of asteroids on C and plan to use the observer pattern described in Game Programming Patterns by Bob Nystrom. (Adapted to C) To do so, I currently have 2 files, a stats system (stats.h/c) and the actual observer pattern code (event.h/c). (Relevant Source code below)

My problem is that stats.h/c requires access to structs and enums defined in event.h, but event.h has a struct that contains a union with a struct defined in stats.h, and I don't know how to solve the circular dependency.

stats.h and stats.c (implementation of statsOnNotify lies in C file)

struct Stats { ... };

// statsOnNotify requires struct Observer and enum EventType, defined in event.h 
void statsOnNotify(struct Observer \*observer, enum EventType event, void \*data) {
  switch (event) { 
    case ...: { 
      //Access Observer union to access the struct Stats data 
    } 
  break; 
  }
}

event.h

enum EventType { ... };

struct Observer;

// Requires struct Observer and enum EventType. 
typedef void (\*NotificationHandler)(struct Observer \*observer, enum EventType event, void \*data);

enum ObserverType { ... };

// struct Observer requires struct Stats, defined in stats.h 
struct Observer { 
  enum ObserverType type; 
  union { 
    struct Stats stats; 
  } data; 
  NotificationHandler onNotify; 
};

r/C_Programming • • 12h ago

Streamside: a native C viewer for Twitch, Kick, and YouTube Live with embedded chat

Thumbnail
streamside.lessif.org
1 Upvotes

Sharing a C project I've been working on: a single-window viewer for Twitch, Kick, and YouTube Live streams + chat without Electron, Python, or yt-dlp.

It embeds libmpv into an SDL2/OpenGL window alongside a custom chat pane (Twitch IRC over WebSocket, Kick Pusher WebSocket, YouTube InnerTube polling, plus inline emote/emoji rendering) and resolves HLS directly with libcurl. Builds statically on Linux and cross-compiles to a standalone Windows exe with mingw-w64.

Demo + MIT source tarball here: https://streamside.lessif.org/

Feedback on the code or build setup is welcome.


r/C_Programming • • 15h ago

Project I wanted a modern alternative to C, so I started building Elash

0 Upvotes

So, I like C. I like how simple it is and I just like using it. I'm tired of overcomplicated languages. But of course C is not a perfect language. There are so many features I'd really like to have. So many things that could be improved or redesigned in a better way. So many bad decisions and suboptimal tradeoffs.

If you don't care, you can just scroll to "The Elash language" section. I know I should've show some code example here to actually get you interested but I currently don't have much to show. But... here's a "game" made with SDL3 in Elash!

My problems with C

I'm very happy with C's philosophy, but there are some things I've always wished it did differently.

  • Native tagged unions: In C, you usually build them as a struct with an enum tag plus a union (or use tricks like a common tag header in every variant). All of these require a lot of boilerplate, and there's no pattern matching. I don't think full pattern matching is strictly necessary, but I'd LOVE something like if (SomeVariant v = my_union) use(v);. In C it's more like if (my_union.kind == MYUNION_SOME_VARIANT) use(my_union.as.some_variant);, and you repeat the field name every time. However you define it, it's never as convenient as a built-in tagged union, and the compiler can't enforce safety or stop you from accessing random fields before checking which one is actually active.
  • Optional types: For an optional int in C, you use a sentinel value such as 0, -1, or maybe even INT_MAX/INT_MIN depending on which values you don't need. If you really need the whole range, you can wrap it in a struct with a bool has_value; field, which is really inconvenient, at least for me. On the other hand, we have pointers, and they have the standard NULL constant, but the problem is every pointer is "optional": there's no way to encode a pointer that can't be NULL in C's type system, so you rely on comments and docs, and the compiler doesn't read those or enforce them. There are compiler-specific "solutions" like __attribute__((nonnull)), but that's just not the same thing.
  • More advanced preprocessor: Many people will disagree, but I think the concept of a preprocessor separate from the core compiler is a great thing. But CPP is very limited and requires hacks if you want to use it for something more complex. It doesn't support recursion and iteration in a normal way and it cannot evaluate expressions (I mean, it can, but only in #if directives).
  • Slice types: To declare a function that takes a slice you usually write (int* xs, size_t count), and to store one you need two struct fields like things and things_count. That's inconvenient. It's much better to store a slice in one variable without defining your own struct every time you need a slice of a type that doesn't already have one. And int[] xs looks better than IntSlice xs (:
  • Declaration syntax: No need to explain. It's just terrible. But people don't get why. It's not because the type comes before the variable name. You can design readable, consistent type-first syntax. What separates good and bad declaration syntax is whether it reads naturally left to right or right to left without parentheses. Just reversing C's syntax doesn't make it readable. (*signal(int, (*)(int): void)): void isn't any better than void (*signal(int, void (*)(int)))(int);. But void(int)* signal(int, void(int)*); is, because it reads cleanly left to right. Typedefs only partly solve this, and there are still footguns like int* x, y;.
  • Weak type aliases: Typedefs in C are only aliases. You can use the typedef and the original type interchangeably. You can wrap the type in a struct, but then you lose access to operators etc. It would be nice to have some way to define "strong type aliases", like in Go.
  • No defer: Pretty obvious, defer statements are really useful and C just doesn't support them. If you follow recent C standards you may know that this feature is slated for C29, but that standard will be released around 2029 and it'll take a few more years before it's production ready.

There are so many other examples, that I will not explain all of them, but a few more examples are: Bad standard library, No built-in collections, char vs unsigned char vs signed char, Built-in string views, Arrays as first class values, Loops over collections, Embedding files at compile time (C23 added #embed but most compilers don't support it yet), Anonymous functions, Implicit narrowing conversions, ...

The Elash language

I know of C3, Zig and other languages that tried to "replace C" but none of them is quite what I wanted, and also I want[ed] to learn langdev and compiler architecture, so I decided to create my own programming language, called Elash (the name doesn't mean anything, it just sounds cool).

It obviously won't "replace C", and that was never the goal. As I already said, I wanted to learn compilers architecture and experiment with designing my own language just how I want to.

It's meant to be a really simple, relatively low-level language that is [semi-]familiar to C developers, convenient to use, and fixes the issues listed above.

I started the project about 9 months ago, I took a couple of breaks but I was working on it regularly for a very long time, initially with a friend of mine but later I became the only maintainer. The project isn't finished. In fact, it's still in the early developement stage, though it's already (kind of) usable for simple tasks. Writing a programming language takes time and you can’t just finish it in a week like many vibecoded languages posted here and on other subreddits.

The compiler is written in C using the LLVM C API (it's built as a multi backend compiler from the start though currently LLVM is the only backend)

I'm looking for people interested in the project; if you want to contribute to the language, share your ideas or just see how development is going, you might want to join the Discord server I've just created. And here is the GitHub repository.


r/C_Programming • • 18h ago

I built CLAP to make it easier to compile a C file on Windows

0 Upvotes

I maintain CLAP, an open-source command-line frontend for C and C++. The use case is a small C program on a fresh Windows machine. With Python installed, you can install CLAP with `python -m pip install clap-compiler` and build a local `main.c` with `clap build main.c -o hello`. If needed, CLAP downloads a pinned Zig/Clang toolchain on the first build. It also supports multi-file projects and CMake.

I’d like feedback from people who teach or learn C on Windows. What would you expect a tool like this to show when the first build fails, and what would make the compiler setup easier to understand?

Source and examples (MIT): https://github.com/BRATAN-CORP/clap

c now is easy, as never before...


r/C_Programming • • 1d ago

Project HimitsuObfuscator: Whitelist-driven C/C++ obfuscator with LLVM 17

Thumbnail
github.com
1 Upvotes

Obfuscation can cause build errors or unexpected runtime behavior when transformations are applied too broadly.

I built each obfuscation pass around a whitelist, so only instructions considered safe for each transformation are selected.

It supports Linux on x86_64 and aarch64, with control flow flattening, bogus control flow, instruction substitution, string encryption, and basic block splitting.


r/C_Programming • • 1d ago

Project Wrote a multi-core-native, SIMD lossless compression codec, originally for my engine, but just released to github with permissive license!

Thumbnail
github.com
0 Upvotes

Hey everyone,

I originally built this compression algorithm for my own game engine because I wanted an open-source middle ground between LZ4 and Zstd for game dev workloads (paks, streaming assets, snapshots, small netcode packets). Full disclosure: I have background in network and low-level optimization, and I used AI to help me bridge the domain gap in compression itself while steering the architecture, profiling, and verifying everything on real hardware.

It turned out useful enough that I split it into a standalone zero-dependency library + CLI in both C11 and native Odin (100% wire-compatible, Apache-2.0, Linux/macOS/Windows):

https://github.com/JoseIgnacioAragon/axz

Quick numbers on the standard 202 MiB Silesia corpus (Intel Core 7 240H, AVX2, in-memory):

  • AXZ -1: 2.21x | 3.36 GiB/s 1T / 17.0 GiB/s 16T decode
  • AXZ -5: 2.90x | 3.24 GiB/s 1T / 17.0 GiB/s 16T decode (matches Zstd -1 ratio while decoding ~2x faster 1T and ~11x faster 16T, since standard Zstd frames don't parallelize decode)
  • On a 32T Ryzen 9 7950X (AVX-512VBMI2) it scales up to 58 GiB/s multi-core decode.

It's multi-core native in the wire format, skips bit-level Huffman/ANS in favor of SIMD planar tables, and includes 11 per-chunk pre-filters (RGBA8, Float4_Xor, Delta, SoA, etc.) plus 8-byte micro-packets + 8 KiB dictionaries for small RPC/netcode payloads. ARM64 NEON isn't in yet (runs scalar fallback for now), and -5 is intentionally slow to encode for offline asset cooking.


r/C_Programming • • 2d ago

Video Coding a fractal Kaleidoscope using C & GLSL

Thumbnail
youtu.be
11 Upvotes

In this video I create a classic kaleidoscope fractal animation using Raylib, C and GLSL.

I follow these steps:

  1. First, I split the screen into slices (like a pizza) using polar coordinates.
  2. Then, I create a well-known pattern in fractal shaders: sin(x) * sin(y), inside each slice.
  3. Next, I add a color palette to generate some nice colors.
  4. Finally, I use time as a parameter in different parts of the shader to animate both the pattern and the colors.

Source code:
https://github.com/FractalCodeRicardo/zen-programming/tree/main/kaleidoscope

C part

#include <raylib.h>

#define size 800

float time = 0.0;
int main() {

  InitWindow(size, size, "Kaleidoscope");
  
  Shader shader = LoadShader(0, "kaleidoscope.glsl");
  int timeLoc = GetShaderLocation(shader, "time");
  
  while(!WindowShouldClose()) {
    
    time = GetTime();
    SetShaderValue(shader, timeLoc, &time, SHADER_UNIFORM_FLOAT);

    BeginDrawing();
      ClearBackground(BLACK);
      BeginShaderMode(shader);
        DrawRectangle(0, 0, size, size, BLACK);
      EndShaderMode();
    EndDrawing();
  }

  CloseWindow();
}

GLSL part

void main() {
  float pi = 3.1416;

  vec2 uv = gl_FragCoord.xy / 800;
  uv = uv - 0.5;

  float angle = atan(uv.y, uv.x) * time * 0.3;
  float radius = length(uv);

  float slices = 3;
  float size = pi * 2 / 3;
  float internal_angle = mod(angle, size);
  internal_angle = abs(internal_angle - size /2.0);
  
  vec2 internal_point= radius *
    vec2(
        cos(internal_angle) * radius,
        sin(internal_angle) * radius
        );

  float pattern = 
    sin(internal_point.x * time *10 * 0.5) * 
    sin(internal_point.y * time *10 * 0.5);

  vec3 c = palette(pattern + time * 0.5);

  color = vec4(c, 1);
}

AI Disclaimer:

I used AI to understand the fractal then I coded my own version


r/C_Programming • • 2d ago

C beginner

7 Upvotes

hello, i love the c programming language, and i want someone that is also a beginner like me to help each other get better, right now working on a project "text editor"


r/C_Programming • • 2d ago

Question Design choice with enums and strings

6 Upvotes

I'm working on a C minecraft clone, and I've been refactoring a bunch of my block code. Previously a "block" was just an enum, I essentially "hardcoded" the list of blocks in the game itself. Part of the refactor is using a JSON file for defining blocks and their metadata. However, because of this, I've now reached a weird place. The JSON defines the ID as a string. The enum that was BLOCK_GRASS is now a string in the JSON as "BLOCK_GRASS".

The design question I have is should I be referencing a string in my code, and doing comparisons with strings? Or do I need to have some sort of intermediate mapping of string IDs -> enum IDs. The latter seems kind of wasteful since it just means all the benefits of the JSON config file went away.

Not sure what the general consensus is. The strings are going to be in the data section anyways so I don't think I'm being wasteful with allocations here.


r/C_Programming • • 3d ago

Question What is the most high-level C feature in your opinion?

140 Upvotes

I'm asking this purely out of curiosity.

I've been programming in C for a couple of years now, and I recently dived into some x86-64 assembly. I was surprised by how similar some asm concepts were to using C. Known by some as a "portable assembler", C is probably one of if not the most low-level language one can use that is not raw assembly language.

But what is the most high-level feature C supports? Standard library features do not count.

Honestly? I think it has gotta be structs / unions, right? Sizeof is really powerful and having automatic variable offsets that adapt as you upgrade your code is something I totally missed quite a lot when using MASM.


r/C_Programming • • 2d ago

looking for modern c text editors

0 Upvotes

ive been writing c for 6 months now and i keep on hopping onto different ides and text editors because frankly i dont really like them, i have been using vim , neovim , codium and vscode, code::blocks, codelite but i dont really like them especially the last 2. they have a retro look to them and im not a fan. vscode is too heavy for me considering i use a 4gb ram laptop on void linux so im guessing there arent many choices for me in terms of aesthetics but im hoping anyone can help me finally settle down


r/C_Programming • • 3d ago

SOVDEFLATE: A zero-dependency DEFLATE/ZLIB/GZIP engine written from scratch in C11 with AVX2, BMI2, and AVX-512 VNNI

Thumbnail
github.com
3 Upvotes

Hi everyone,

I’ve been working on SOVDEFLATE, an in-house DEFLATE (RFC 1951), ZLIB (RFC 1950), and GZIP (RFC 1952) compression and decompression library written from scratch in C11 with zero third-party dependencies (only the C standard library and OS thread APIs).

Repository: https://github.com/KanatoreIT/SOVDEFLATE

Key technical details:

- Runtime SIMD dispatch: Selects between scalar baseline, BMI2, AVX2, and 256-bit AVX-512 VL + VNNI (for Adler-32) at startup.

- PDF stream handling: Includes sovdeflate_decompress_prefix and an incremental decoder that stops cleanly at the end of a stream without consuming or rejecting trailing bytes (like \nendstream in PDFs), reporting exact bytes consumed.

- Damaged stream recovery: Recovers partial bytes from corrupted streams matching zlib behavior (tested across 11,982 damaged streams).

- Optional C++20 header-only wrapper (sovdeflate_cpp20.hpp) and custom memory allocator with byte limits.

Honest benchmarks (2,000 real DocLayNet PDFs / 445.5 MB uncompressed, i5-11400H):

- Decompression (1 thread): 713 MB/s (vs. 738 MB/s in libdeflate 1.26 — about 3.5% behind).

- Decompression (12 threads): 5,310 MB/s (vs. 6,037 MB/s in libdeflate 1.26).

- Compression (DEFAULT / level 6): 77.7 MB/s at 1.000× size (vs. 46.8 MB/s in zlib 1.3.2 and 127.2 MB/s in libdeflate).

Compression speed is still behind libdeflate and is my main focus for the next iteration. The repo also includes an originality audit script checking against zlib, zlib-ng, libdeflate, miniz, and stb, plus ASan/UBSan test scripts.

I’d love to hear any feedback on the C11 implementation, SIMD paths, or ideas to close the compression speed gap!


r/C_Programming • • 3d ago

When is a small C function worth putting in a header as static inline?

15 Upvotes

I’m splitting some graphics code into smaller .c and .h files. For tiny maths functions called frequently, how do you decide between a normal function in a .c file and static inline in the header? Do you measure a difference before moving them?


r/C_Programming • • 4d ago

Is there such a problem as "C++ style C"?

64 Upvotes

C++ programmers denounce "C-style C++" that uses primitive C features over newer C++ alternatives. Is the opposite a thing in C where excessive emulation of C++ features become a problem or an antipattern? Some possible examples off my head, no idea how common they actually are or whether they are considered bad; you are welcome to add more:

  • Manual move and copy constructors on resource holders
  • Manual vtables and inheritance
  • Manual closure structs
  • Macro-based template instantiation
  • Opaque generic classes that use all of the above

r/C_Programming • • 3d ago

Cortex: A Cargo/uv-inspired package manager and build tool for C and C++

Thumbnail
github.com
0 Upvotes

Hey ,

I’ve been working on cortex (cx), a C/C++ package manager and build tool inspired by Rust’s Cargo and Python’s uv, and I’d love to share it with you and get some feedback.

Why another tool?

Setting up a C++ project with clean dependency management, lockfiles, features, and workspaces often requires gluing together multiple tools and boilerplate CMakeLists.txt files. With cx, you describe your package in a single cx.toml file, it resolves and locks dependencies, generates the underlying CMake project, and drives the build automatically.

Quick example

```bash

cx new hello

cd hello

cx add nlohmann_json --git https://github.com/nlohmann/json --tag v3.12.0

cx run

```

Key Features

• Zero-boilerplate builds: Sources, tests, benchmarks, and examples are discovered by convention (src/, tests/, benches/, examples/). Supports mixed C (C90–C23) and C++ (C++98–C++26), including C++20 modules (.cppm, .ixx).

• Flexible dependency management: Pull dependencies from registries, Git repos, local paths, system packages (find_package), or vcpkg. Any existing CMake, Autotools, or SCons project works out of the box as a Git or path dependency.

• PubGrub version resolution & lockfiles: Uses the PubGrub solver (like uv and pub) for clear conflict explanations.

• Cargo-style features & workspaces: Supports optional dependencies, feature flags, and multi-package workspaces sharing a single lockfile and target/ directory.

• Built-in developer workflows: Comes with cx test, cx bench, cx fmt (clang-format), cx lint (clang-tidy), cx doc (Doxygen), cx vendor for offline builds, and built-in sanitizer/LTO build profiles.

• IDE & CI friendly: Generates standard CMake projects (cx generate) and JSON metadata (cx metadata) so your existing IDE setup works seamlessly, plus --locked and --offline flags for CI.

Current Status & Caveats

• First Release & Self-Hosting: This is the very first release. Right now the repo still includes its bootstrapping CMake files, which will be removed in the next release now that cx can build itself.

• Public Registry: There isn't a central public registry yet, though cx works directly with Git repositories, local paths, vcpkg, system packages, and includes a lightweight self-hosted registry server (cx-registry).

Links

• Github

• Docs

You can install prebuilt binaries via the install script in the README or build it from source.

I’d really appreciate any feedback, bug reports, or thoughts on what would make this genuinely useful for your C/C++ workflows!

Thanks and please leave a star.


r/C_Programming • • 4d ago

Question How do you catch fixed-point overflow before it becomes a visible bug?

0 Upvotes

I’m working on some graphics code in C using fixed-point arithmetic. When something looks wrong, it can be hard to tell whether I’ve lost precision or an intermediate calculation has overflowed.

How do you check this while developing? I’m especially interested in catching the first bad calculation, before the result gets passed through several more steps.

AI helped word this question.


r/C_Programming • • 4d ago

If char[] is like a covered pointer, why const char * points to an static piece of memory and char[] creates (or copies from the static) memory in the stack?

26 Upvotes

The title says it all. Im pretty beginner in C and maybe i'm confusing some things with my first afirmation:

> If char[] is like a covered pointer...

I tried to search a lot but my doubts about this subject couldn't get away. (idk why i said in a so metaphorically speaking haha srr)

Thanks!


r/C_Programming • • 4d ago

Barriers, Volatile, and Atomics: How PostgreSQL Orders Memory Accesses

Thumbnail postgr.es
3 Upvotes

r/C_Programming • • 4d ago

Question Need help from senior C programmers

0 Upvotes

Can you all please suggest me the best YT channel (or any other resources) to watch C from, see i kinda know the basics now but the depth is missing, i was seeing yt channels like codewithharry but i think the depth isnt enough, so would be great if anyone helps me out


r/C_Programming • • 5d ago

Tidy translucent typedefs

Thumbnail tavianator.com
36 Upvotes

Recently discovered a nice way to get custom warnings with Clang, so I wrote it up.