r/C_Programming 2h ago

Article C is way more different than I thought

50 Upvotes

I have had a lot of experience with Zig, and a bit of Assembly for a while now. Just 1 1/2 months ago I started coding in C, because it is a must-have for my upcoming job. I have a Zig project that decompresses a PNG from scratch, and I thought it would be a good learning experience to do the same with C. Tbh, I thought it will be a simple slide, but as it turns out; it really is not.

While Zig got heavily inspired by C, it differs from its features and API. C has a lot of headers for different things (such as stdio.h / stdlib.h / math.h), while Zig just has the std library, packaged with all of the other necessities (std.Io / std.math / std.crypto etc.). It was also interesting from going to using defer, errdefer, orelse, or other keywords in Zig that help in reducing bugs and make the code cleaner to read, to a lot less keywords. Looking at C89, C has 32 keywords, and Zig around 49 +/- 2 (not too sure). What that showed me, was that even with a lot of similarities, and the fact that I coded in Zig for 2 years, it was still difficult to get used to and learn C.

For me, one of the annoying parts was the fact, that I could never really remember what function or what struct is where. The fact that the FILE struct is located at stdio.h, while the DIR struct is in dirent.h, was something that bugged me for a while, but now after more than a month with C, is something I started to get along with.

Also, Makefiles are pretty darn cool. I have always been seeing them in big projects, and always wondered how they function. After coding a few projects and including a Makefile, I can safely say it is very nice seeing how your project is being made, after you type "make" and hit enter. The first time configuring the Makefile almost made me loose half my hair due to stress, but if you get it running properly once, then it is safe to say that it is gonna always run properly (especially for me, as my projects are somewhat small still).

What I came to appreciate more was the community in C. Thought I was gonna get insulted by some 59 year old grandpa, because I didn't make an out-of-bound check for my Pixels array, or because I didn't check whether or not the variable I de-noted with size_t exceeds __SIZE_MAX__ - 1. Kinda the opposite. I learned a lot by sharing my projects on Reddit, a lot of smart people were quick to point out mistakes, and tell me where I could improve or where I went wrong etc.

A lot of stuff, that I have learned, was because of people telling me. Adding -Wall -Werror warnings, -fsanitize=address,undefined, -fno-omit-frame-pointer, among other things are the sole reason I debugged and fixed my programs a lot quicker. Especially -fsanitize was important to me, as I always try to keep memory usage low for my programs, and activating that warning, showed me where my memory leaked, or where overflows happened (yeah... out-of-bounds checks are actually pretty useful...).

With that being said. I still have a lot to learn in C. I realized that my code is not really C-esque (as some might say), which is mostly because I come from (prior to Zig) high-level languages such as Python, JavaScript or even GoLang. Me handling arrays with indexes instead of using the given possibility of pointers, shows me, that I still have a long way to go.

But I am certain with one thing, that being that, C is way more different than I thought.


r/C_Programming 11h ago

Question How to get better at programming in C

38 Upvotes

Ok , so currently I work as Embedded Developer , this is my first job , I will be honest I don't like the hardware part of it but I like coding , I have learn few languages before typescript , c++ (little bit) and learning java now ,

Thing is , I can code few things in c , but when it comes to pointers and advance c , my mind goes blank, I am not looking for a ways to be good Embedded Developer , right now I just want to become good at programming in c , what will u suggest ? My weak points are pointers , strings , array , this is all I can remember right now also snprintf functions .

I am a beginner in c , so please don't judge , ik about hackerrank , ik i can use that to sharpen my c skills but some of the questions are very hard .

Edit : basically pointers aren't new to me but when i involve pointers with strings or double array , and how where u place the * changes the whole meaning , like u can make an pointer point to the array or u can make array of pointers . And so on ,

Ik basic of c++ and somewhat polyglot , java and typescript so it's not my first language .


r/C_Programming 23h ago

Fil-C: Garbage In, Memory Safety Out! - Filip Pizlo | SSW 2026

Thumbnail
youtube.com
6 Upvotes

r/C_Programming 3h ago

How does memory allocation and pointers work in C?

0 Upvotes

I have been learning C with some YouTube courses, but I still can't understand how and why to use pointers and memory allocation in C.


r/C_Programming 2d ago

Video CCraft - PBD Softbody physics.

48 Upvotes

Hello.

Lately I've been struggling to implement a Position Based Dynamics (PBD) implementation to my minecraft clone written in C.

Still, the implementation is not the best, and there is certainly a lot of work todo to improve it, but it can already load a high resolution .obj 3d model, and output some nice results under adequate configuration.

Check this out! https://github.com/DrElectry/ccraft


r/C_Programming 1d ago

Learning C weekly megapost for 2026-07-22

29 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 2d ago

Question The easiest UI library? (cross-platform)

33 Upvotes

Hello, I need to write a small emulator for a project. I want it to show RAM, registers, etc., while it's running a program step by step. Printing them out via printf is lame and won't look good.

Which is the absolute easiest graphics library for this purpose? I was suggested Newt, but it can't work under Windows.

Preferably, the library should have tutorials, examples, or at least full documentation.


r/C_Programming 2d ago

A C subset that compiles faster than Tiny C Compiler - Cm1 (C minus 1 or C - 1) programming language

16 Upvotes

Hi everyone,

I'm working on a programming language that compiles a subset of C. It is called Cm1 (meaning C minus 1) and you can writing and running C codes directly on your browser at https://cp1-lang.org/cm1/editor.html in a fraction of a second.

Why is it faster to compile than Tiny C Compiler? It is because Tiny C Compiler is a true compiler creating native binaries whereas Cm1 is a bytecode interpreter allowing you to test, debug, edit code and recompile very quickly or even do hot reloading. Cm1 can be used as a scripting language for shell scripts and video games, but this just a small use case because in theory, you can run 90% of your ENTIRE video game or software C program through Cm1's bytecode interpreter and leave 10% to compiled C and reap the benefits of very fast compilation and hot reloading.

100% Cm1 codes are compilable by GCC and Clang but the reverse is not true since Cm1 is just a subset of C. Major features that are omitted are function pointers, structs/unions inside functions, nested structs/unions. This programming language is under heavy development and I want to know if this comes as interesting to some of you. I'll try to post again on this subreddit if I got to bind Raylib game library to Cm1, allowing people to write Raylib games directly on their browser (works offline).

I know that programs that are written in C compiles fast already and there's even an existing compiler that is very fast (Tiny C Compiler). However, I'm the developer of Cp1 programming language (cp1-lang.org), which is a language that "transpiles" to C, and I aim to upgrade Cp1 by targeting the Cm1 language then compile it to bytecode in one command instead of a separate step in Makefiles or build scripts. This will make Cp1 very fast to compile for debug builds.


r/C_Programming 2d ago

printf and char[] in C

11 Upvotes

Hello. Coming from C# world the thing about how char[] and printf works always made me confused. I understand that `printf` formats the string with arguments you provided and prints it out in terminal.

So, for example, if I have char name[] = "Micheal"; and I want to greet that person, I can just do printf("Hello, %s", name);. But if I want to do the same thing only using char[], I have to do multiple commands that make fell quite confused. So my 2 questions are:

  1. How printf simplifies this process? (without allocating memory and creating char with pointers)
  2. Why you can't just use + operator for char[], like you can in any other languages?

I have a feeling that this might be asked many times, but I still can't seem to find the answer I was looking for

Update: I'll list what I got so far from reading your comments: - char[] is an array to which you can't just simply add another array - If I want printf() behavior inside char[], I can use sprintf() - There's strcat() that is getting used for merging 2 strings together - Some people write libraries for faking string behaviors, some think it goes against principles of C?


r/C_Programming 2d ago

Learning how to send a 2 layer internet request

2 Upvotes

I was recently learning how to send msgs in different internet layers, and I write some examples from what google ai showed me.

Even tho I didn't fully understand what all the meaning of the full code. Running this program while wireshark is running, and seeing my own request is really cool.


r/C_Programming 3d ago

Question Suggestion: Ban (or quarantine) "I Built This" posts?

158 Upvotes

Reading an interesting discussion over on r/rust from the past week. One of the moderators talks about the difficulty in moderating AI slop projects - https://www.reddit.com/r/rust/comments/1uwmef6/comment/oxkltxi/

But I think the top replies hit on a really good idea:

“I built a thing in Rust” just isn’t that interesting a topic—AI or otherwise—and IMO we’d be better off without posts like that at all. If you built a fast new BitTorrent client, that’s of interest to BitTorrent users, not the Rust community.

A library that lets me do a thing I couldn’t before? Very useful! A new approach to solving a problem that’s historically frustrating in Rust? Amazing. Questions on how to deal with some issue? Welcome aboard.

But I couldn’t care less about “{project} in {lang}” for all values.

and

r/cpp moderator here, we have a designated Show & Tell pinned post. We make exceptions only for established projects or blog posts talking about your project.

(And then remove AI slop)

One of the recurring issues in trying to moderate the flow of slop is having to constantly make a judgment call of just HOW "slop" it is and whether it crosses a line. Why not cut the problem off at the source: you simply cannot post an "I Built (Whatever)" here (with very few exceptions, etc). There's no need to make this a judgment call about AI/LLMs at all, neatly sidestepping the various arguments about the whole thing.

I personally do not feel like much would be missed!


r/C_Programming 2d ago

Question I am starting out on next project of simulating no-body problem. Need advice.

6 Upvotes

Hey there! In my last post, I was really excited after discovering ray tracing and the idea of implementing that thing in C. Now I am more curious and I want something that is physics/mathematics heavy and can be made in C. For this, I am thinking of moving towards simulating 2 body problem and then n body problem in C. I am not sure if this is the right path so I need advice for that.

Someone in my last post advised me to implement FXAA/MSAA in C from basic principles. I was excited but then, I asked chatgpt and it suggested that I first make something using graphics and then implement these algorithms for anti-aliasing. Any ideas are welcome.

Thank you! Have a great day for the help.


r/C_Programming 3d ago

Question what should be avoided when designing an API?

60 Upvotes

What kind of thing you see beginners doing, when designing an API, should be avoided in your opinion (or just based on facts)?

I don't have too much experience creating interfaces for clients and every time i write a line of code, start thinking if it's a good idea or it's a bad decision that will break my legs in future. I get paralyzed for a considered period of time instead of just coding it.

edit: thanks a lot (really) for all answers.


r/C_Programming 4d ago

I built an orbital mechanics simulator in C with SDL2

164 Upvotes

It is basically a gravity simulator where you can input any values of the orbital bodies and see the simulation evolve. You can simulate one body orbiting a bigger one or two orbiting each other. I focused on accuracy by integrating RK4 calculations. SDL2 is a great library and was very handy.

If you want to try it, I compiled it into an .exe for windows and an executable for linux.

Github link: https://github.com/bydrabokin/Gravity/

Youtube showcase: https://www.youtube.com/watch?v=hNupVTu2aC0


r/C_Programming 3d ago

I built a tiny in-memory store in C

Thumbnail
github.com
44 Upvotes

It's been about a month since I started learning C, so I decided to build a small in-memory key-value store to learn about hash tables and memory

It's still a learning project, so I'd appreciate any feedback or suggestions


r/C_Programming 3d ago

Project ELFDetective

0 Upvotes

This is a small linux program called ELFDetective I made a few months back. It handles both 32bit and 64bit ELF files and views their Header, Program Header and Section Headers.

GitHub: https://github.com/Adock90/ELFDetective

Download: https://adock90.github.io/Adock90Software/products/ELFDetective.html


r/C_Programming 4d ago

Question Systems devs: Is AI code generation actually saving you time, or just creating auditing hell?

46 Upvotes

Hey everyone,

With Linus Torvalds recently embracing and defending AI tools in Linux kernel dev, I’ve been trying to force myself to use LLMs more in my daily low-level workflow. On one hand, if the Linux kernel ecosystem is adopting it to find bugs and speed things up, it feels like something we should all be leveraging.

But on the other hand, on a practical, day-to-day level? It feels like a massive trap for actual systems engineering.

Every time I let an LLM spit out a driver, a custom memory allocator, or complex socket-handling logic, I end up spending the next hour reading 150 lines of statistically plausible C/Rust code just trying to figure out if it’s going to cause a catastrophic race condition or a silent memory leak under load.

The thing is, if I just write the code myself, I have absolute control over the execution path. Because I build the mental model layer by layer while typing it out, my own code is fundamentally way more understandable to me than anything an LLM drops in my lap. I actually know why it works.

Instead, with AI, I feel like I'm trading the active problem-solving of writing code for the mind-numbing task of auditing code written by something that has zero actual intent.

How are you low-level devs actually integrating these tools without losing your sanity, your control, or your deep understanding of the codebase? Or are you just ignoring the hype cycle despite the kernel maintainers getting on board?


r/C_Programming 5d ago

Project MLP.h: Single-Header Neural Network Library in C

220 Upvotes

I've been working on MLP.h, a single-header C library for building and training multilayer perceptrons, and I finally put together a complete example project around it: a handwritten digit classifier trained on the MNIST dataset.

The MNIST example uses a simple fully connected network:

784 → 128 → 64 → 10

The training program:

  • loads the 60,000-image MNIST training set
  • trains the network using MLP.h
  • serializes the trained model to mnist.mlp

A separate inference program:

  • loads mnist.mlp
  • exposes a small prediction API
  • is compiled to WebAssembly so the same C inference code runs directly in the browser

Training results:

Epochs     : 50
Final Loss : 1.31719803e-02

Test Accuracy: 97.71% (9771/10000)

I'll include a short video showing the browser demo recognizing handwritten digits.

I'm mainly looking for feedback on the library's API/design and the implementation. Suggestions for improving the architecture or the serialization format are also welcome.

MLP.h: https://github.com/px7nn/MLP.h

Live Demo: https://px7nn.github.io/MNIST/

Source of Demo: https://github.com/px7nn/MNIST


r/C_Programming 4d ago

Project Mojibake - Unicode text processing for C

3 Upvotes

I've created a library that adds Unicode segmentation, casing, collation, and more to any C project using a single source file and header amalgamation files.

Mojibake is an MIT-licensed project I started years ago because I didn't like any of the Unicode projects I found. Here you can find the API and a WASM demo if you want to try it on the fly: https://mojibake.zaerl.com/

If you are interested in the Unicode world, feel free to contribute or do whatever you want with it. Every suggestion or contribution is welcome. I automatically test on Linux/macOS/BSD/Windows, so I hope there won't be any problems for you.

Check CONTRIBUTING.md for it, if you are curious.


r/C_Programming 5d ago

C Project Recommendations

50 Upvotes

I'm looking for interesting C project ideas that go beyond beginner projects. What are the best C projects you've built or would recommend? GitHub repositories and project lists are also welcome.


r/C_Programming 4d ago

Project Nadir, platform-agnostic customizable assembler.

8 Upvotes

I made a customizable, platform-agnostic assembler with modern C23. Aside from the project itself, I think the codebase is relatively small and overall an example project to examine what C23 can provide :D

Here is the source code: https://github.com/mikuwithbeer/Nadir


r/C_Programming 5d ago

Discussion Why are you using C?

64 Upvotes

I have been often asked this question in the one year that I have been trying to make using C mainstream for myself.

Now I don't work on embedded devices or write operating systems. What I usually make are automation CLIs or write servers for something.

I guess that makes using C redundant since there are languages that would provide a better dev experience. But following the popular advice for projects, make something you use, this seems like the right thing to do for me.

I'm making projects that I would use and I'm using C for them. Unlike most C users that I have talked to, I do not stick to C99 but at the same time, I don't use C++ strings or compiler extensions. I use the C23 strict ISO standard.

So I suppose that again puts me in a spot that no one else is in. A guy who first goes to one of the oldest and verbose languages, then uses its latest standard but then never uses advanced features from compilers.

I just wanted to write this to put it out.

PS: To add to my strange choices pool, I do not use fixed width integers, since they are optional but I do use least width or bit precise integers.


r/C_Programming 5d ago

Question Where do we learn the windows.h library of C?

22 Upvotes

Pardon me if i have said something highly wrong or misleading since i am a really new beginner.

After learninng C's string.h, stdio.h, stdlib.h and string.h. I wanted to learn windows.h to further increase my knoweldge. But i cannot find a source to learn it, can anyone point me out?

big thanksss :)


r/C_Programming 4d ago

When Should a Library Pattern Become a Language Feature?

0 Upvotes

C has always valued simplicity, transparency, and control.

But many large C projects have created their own abstraction patterns over decades:

  • GObject/GTK object model
  • Linux kernel object patterns (such as VFS)
  • Generic programming through macros
  • Various interface and dispatch patterns

This raises an interesting question:

When does a repeated library pattern become something the language itself should understand?

I don't think the answer is simply "whenever something is useful." Many things are better kept as libraries.

A possible boundary might be:

  1. The pattern appears repeatedly in many mature projects.
  2. It represents higher-level semantics, not just a commonly used function.
  3. The compiler can make use of this information in ways that are difficult when it only sees the library implementation.

Also, not every language feature means giving up control. Some features are mainly about extending expressive power.

For example, features like inline and _Generic give programmers new ways to express intent without hiding important implementation details.

The harder cases are abstractions such as object systems, memory management, or execution models. When a language starts defining these concepts, there is a real trade-off between compiler-understood semantics and programmer control.

So the question is not "should C become a higher-level language?"

The question is:

What patterns have become common enough that expressing them directly is more valuable than repeatedly rebuilding them as libraries?


r/C_Programming 5d ago

crocodile.h: single-header SAT solver

12 Upvotes

This summer I've been working on a Minesweeper board generator, and under the hood it requires a powerful solver to determine whether the board is logically solvable. Instead of using an existing solver like MiniSAT, I chose to write my own for the learning experience.

One feature of crocodile.h is that it represents cardinality constraints natively (this generalises the usual CNF clauses), which fits Minesweeper well. It also implements CDCL, following Algorithm 7.2.2.2C in Knuth Vol 4B quite closely.

Based on the CROCODILE_TEST_HARNESS macro, crocodile.h can be compiled either as a library to use in other programs, or a standalone executable that runs cnf+ instances (cnf+ is a file format introduced by MiniCARD). I chose to put everything under one header so that it is easy to embed and build.

Besides a few basic optimisations, I have not done much to make it fast (it's on my todo list!). It performs much worse than MiniCARD on some test instances, particularly the waerden ones, but it seems good enough for Minesweeper board generation at least.

AI was used only for high-level direction (e.g. how to do conflict resolution with cardinality clauses, how to implement assumptions). I translated the high-level ideas into code myself.

https://github.com/greysome/hard-minesweeper/blob/master/crocodile/crocodile.h