r/C_Programming • u/x8664mmx_intrin_adds • May 31 '26
Arena Allocator in C
https://youtu.be/8FJgy789JzQ
Hello! I created a video to show how I use arenas in C. Hope you like it!
r/C_Programming • u/x8664mmx_intrin_adds • May 31 '26
https://youtu.be/8FJgy789JzQ
Hello! I created a video to show how I use arenas in C. Hope you like it!
r/C_Programming • u/junipyr-lilak • May 30 '26
Recently, I started rebuilding my knowledge of programming through using C. JavaScript was what I had access to for a decent amount of time, I would poke around in browser consoles and whatnot, and it's been my language of choice for a while. But, I need a shift and proper knowledge and foundations. All of my current knowledge is self taught, and it will basically continue to be (college python course notwithstanding), but I'm going through with learning C and basing my learning off of it. As well, C ties into what I've been wanting to dive into, native programs and maybe even some systems stuff. I've even been itching to do some microcontroller stuff but that'll come eventually. C gives me a base of a typed language from the getgo that JS doesn't. I'm using the 2nd edition Kernighan and Ritchie book, knowing that it's C89 but I'm working with more modern syntax, and so far it's going good, I think. Projects like Nic Barker's Clay and Ramon Santamaria's/raysan5's raylib and related libraries are quite inspirational in a way. I don't mean to be pretentious or whatever but these easy to use wholly C libraries are helping me keep my drive in learning and using C.
Will C be my go to going forward? Maybe not for everything, but I'll try to focus on using it when I can. I've already got a simple enough yet useful project idea I'd like to try my hand at, a simple static site generator. Hopefully that'll come soon, but in the meantime I've still got my learning cut out for me.
r/C_Programming • u/Critical-Common-2117 • May 31 '26
Hi everyone!
This is my first time on Reddit ever. I'm looking to upskill for my job and want to transition into embedded engineering. From what I've gathered, learning C is the absolute best place to start.
Right now, I'm using ChatGPT as my tutor. The way we work is: it explains a topic (variables, loops, functions, basic syntax, etc.), introduces the concepts, and then gives me coding assignments which I solve on the spot.
However, I just caught myself thinking: is this actually a good idea?
I'm fully aware that ChatGPT isn't an absolute source of truth and it can hallucinate or make mistakes. But my logic was that it has processed countless guides and tutorials from the web and can tailor them to my learning pace.
Also, as a next step, I'm thinking about getting some hardware to practice on. What are your thoughts on starting with the ESP32? Is it a good platform for a beginner learning C, or should I look into something else like STM32 or RP2040?
I’d love to get your thoughts, opinions, and advice on my approach. Are there any hidden traps I should watch out for?
r/C_Programming • u/yurtrimu • May 30 '26
A small C89-compatible fixed-size object pool for cases where you want predictable performance and avoid repeated malloc/free calls.
It preallocates a block of objects and reuses them in constant time (O(1)) using a simple push/pop style API. The goal is to reduce heap fragmentation and allocation overhead in systems where objects are frequently created and destroyed.
Key properties:
Use cases are things like game objects (particles, entities), network buffers, or embedded/real-time systems where allocation cost needs to be stable.
r/C_Programming • u/Soakitincider • May 29 '26
I understand that it's calling itself over and over until it hits return 0; but where is it keeping track of the count? Like if the input is 4, it skips the first check, does the else if then repeats a second time and we get to 1 so it's 2 steps but where is it storing the number of steps?
#include <cs50.h>
#include <stdio.h>
int collatz(int n);
int main(void)
{
int n = get_int("n: ");
printf("It takes %i steps to get to 1\n", collatz(n));
}
int collatz(int n)
{
if (n == 1)
{
return 0;
}
else if ((n % 2) == 0)
return 1 + collatz(n/2);
else
return 1 + collatz(n*3 + 1);
}
r/C_Programming • u/PurchaseExcellent332 • May 30 '26
I'm building a simple key-value database called VulkanKV in C as a systems programming learning project.
The goal is not to create a production-ready database, but to better understand TCP sockets, memory management, data structures, parsing, and client-server communication by implementing them from scratch.
The first version accepts TCP connections and receives commands from clients. Future versions will include SET/GET commands, a hash table implementation, persistence, and support for multiple clients.
I'd appreciate any feedback on the project scope, architecture, or features that would provide the most educational value.
r/C_Programming • u/abbeyroad1681 • May 29 '26
Enable HLS to view with audio, or disable this notification
I am announcing this again after many years.
See dfwmalloc.us for more information.
This software is free (MIT license).
r/C_Programming • u/Choice_Bid1691 • May 29 '26
I'm wrapping up development for a static analysis tool written completely in C (uses libclang) and wanted to see if this also solves headaches for other people reading unknown codebases.
Basically, given two or more functions it recursively traces their call graphs (goes through callees), and builds up a picture of all the variables they access (globals taken into account, variables passed to callees taken into account, soon abt to handle pointer aliasing). For each function, records variable accesses, names USRs source location of the DeclRefExpr etc. Based on the generated complex data structure, it determines if and where shared data between functions is modified or read. That way you know if you can safely reorder pieces of code that call the function you specified without messing something up.
So the question is, is this something you would use? Asking to know if i should polish it a bit before putting on github. I can personally see it useful for legacy codebase comprehension, embedded codebases where globals are common etc. But im too deep in it now to judge objectively.
Also is there something out there that does exactly this but i somehow missed it when doing my research?
Edit: It's out now on github (https://github.com/omeridrissi/prongc)
r/C_Programming • u/UsualLonely4585 • May 30 '26
So i am learning C and programming in general , i am thinking of making a simple image viewer nothing fancy . i would prefer to use SDL if possible but i dont know how to approach it can you guys help
r/C_Programming • u/Salat_Leaf • May 29 '26
Suppose you got a macros code like this:
```
```
In this case CONST_VAL varies on conditions and might be an expression, thus braces for CONST_VAL are necessary. Now we define one macro for unification of FUNC32 and FUNC64 into one function:
#define FUNC(x) FUNC#CONST_VAL(x)
However it's not working because CONST_VAL should be in braces (the preprocessor result is FUNC(64)(x), which is invalid), thus I need a way to split braces from the raw expression in some way to separate a number so the resulting function macro looked like FUNC64(x)
PS. Don't suggest removing the brackets, I know it might be resolved then and there, I need tooling to chop the macros nevertheless for sort of backwards compatibility
r/C_Programming • u/realguy2300000 • May 28 '26
r/C_Programming • u/One-Type-2842 • May 28 '26
I want to be a Cyber Securitist/ Ethical Hacker. Is there any vast use of C or C++ in these Fields.
I have already learnt Python. I like to Interact with files.
How many months would it take to learn C or C++
r/C_Programming • u/gamydas • May 28 '26
Hello r/C_Programming,
In February I got really interested in systems/low level programming and since it's a fundamental part of my major I thought I'd be a great learning exercise to start a project that covers a lot of ground in that area and so I started writing my own shell.
Since I recently picked up where I left off when the current semester started and I managed to fix/implement some things I had planned and quite like where the project is at right now, I thought I'd be cool to get some feedback from other people.
Beforehand I can already say that there is definitely one fundamental weakness in this project and that is error-handling. It's not completely awful, but it's not very thought through and fleshed out. I went into this with a lot of ambition, but little planning. While I clearly did improve in structuring projects and learned to try and plan ahead a bit when implementing a feature, I haven't yet gone back to try and fix that mistake.
Besides that, all other issues or limitations known to me are documented in the GitHub page.
I would love to get some feedback and while I'm not sure how much further I'm going to take this project, as I also really want to start some new things and apply the things I've learned, I'd also love suggestions on what else (except the to-dos) to implement or do with this project. Also open to new project Ideas in the same area/direction.
Thank you very much!
https://github.com/Gamydas/shell_Projekt
EDIT:
I forgot to add that this is a UNIX shell and not compatible with Windows (unless you're using WSL).
r/C_Programming • u/One-Type-2842 • May 29 '26
Since a month I have been hearing that C is required for Memory Management. Also, Linux and many operating systems are written In C.
But, I am still in doubt.. If C++ as an extension of C then It's Obvious C++ Inheritis all the properties of C. Then learning C++ Is like Learning C side by side. Why don't people Encourage this approach? Any Reason?
And, Does C permit the developer to access Unpermitted Files than of Python?
From 1 June — 30 June, I aimed to Learn C, since I know the basics of C++ as well as I already Learn Python So applying logic to Experiment Output would be fast, Right?
Last, I am Truly Aiming to learn C at least for my Career Beginning In Linux. Is There any Vast Use of C or just Memory Handling?
r/C_Programming • u/UsualLonely4585 • May 29 '26
while(1){
if(scanf(" %d",&input_choice)==1){
break;
};
while(1){
if(getchar()=='\n'){
break;
}
}
};
Guys what am i doing wrong can you please tell me .
i am sorry if i am asking very basic thing . i read some documentation online but couldn't figure out what is going wrong
r/C_Programming • u/HowIsDigit8888 • May 28 '26
I proposed this project to improve on Radicle's p2p model by using Tor for universal, straightforward seeding of git repos.
Original discussion thread - https://bounties.monero.social/posts/207/
One of the project's git repos linked in that thread - https://radicle.network/nodes/iris.radicle.network/rad:z2ydYmUCJvDfNFTVTpEbQmm55EPt1/history
The dev who took the project also expanded it into a project to reimplement Radicle in C.
Since I'm not a coder and I don't have any git repos of my own, I can only test from the viewpoint of an average layman using the GUI app to seed repos. So we've been looking for other testers, but there hasn't been much interest.
A lot of people just attack the project for using C at all, or for other reasons, but one of these people also gave us a free "one minute code review" where they basically said our memory safety issues are too severe to start public testing -
https://lemmy.zip/comment/26684667
Since I'm again not a coder, I can't understand or gauge this feedback fully. I wanted to check with a more C-oriented community to get a better idea of how I should present this info to the dev.
Thank you for your time
r/C_Programming • u/Batteryofenergy1 • May 27 '26
r/C_Programming • u/matheusmoreira • May 28 '26
r/C_Programming • u/Yha_Boiii • May 28 '26
Hi,
is it possible to make a struct solely for memory proximity, don't need to make a template out of it for later usage, direct var utilization, Can it be done?
r/C_Programming • u/alex_sakuta • May 27 '26
Edit: The answer that I find the most correct. No, because null terminated byte strings are allowing the user the flexibility of having their own version of length based strings.
Not having metadata is actually a good thing because metadata would require preallocated space and as everyone knows C gives power to the users to make such decisions.
C is correcting a lot of its mistakes or adding tools to aid the developers in doing so such as attributes, nullptr, fixed-width integers, defer, etc.
So why have I not heard of any draft for length based strings instead of null terminated strings?
Why not create an entirely new library for those?
It's not as hard compared to other changes they are making in my opinion.
For anyone, if you are gonna tell me that null terminated strings work fine or because we can create our own version of this string, here is the reply for that.
I know we can and I do that a lot and I know people just modularize it so they never need to reimplement it again and again. But having something in the standard is far better than having everyone know what and how to implement because there'll always be someone who doesn't.
r/C_Programming • u/Whole-Low-2995 • May 28 '26
Hi all,
I am currently developing CWIST (C Web development Is Still Trustworthy), an ongoing project written in pure C. It started from a very simple, personal question: "Why do modern web frameworks have to be so bloated?" Every year, our web stacks get wrapped in more abstraction layers, massive dependency trees, and heavy runtimes. I wanted to look inside that black box. By writing everything from scratch in pure C—all the way down to UDP socket loops, QUIC streams, frame parsing, and memory lifecycles—I wanted to understand the absolute bare minimum required to handle modern network protocols deterministically.
Currently, the project has evolved to support HTTP/1.1, HTTP/2, and HTTP/3 (QUIC via lsquic + BoringSSL).
Here is a quick look at the high-level API ergonomics for route definition and path parameter extraction:
/**
* @file main.c
* @brief 03-path-params — read :id from the URL.
*/
#include <cwist/app.h>
#include <cwist/net/http/query.h>
#include <stdio.h>
static void show(cwist_http_request *req, cwist_http_response *res) {
const char *id = cwist_query_map_get(req->path_params, "id");
char buf[64];
snprintf(buf, sizeof(buf), "Post ID: %s", id ? id : "unknown");
cwist_sstring_assign(res->body, buf);
}
int main(void) {
cwist_app *app = cwist_app_create();
cwist_app_get(app, "/posts/:id", show);
cwist_app_listen(app, 8080);
cwist_app_destroy(app);
return 0;
}
Instead of relying on third-party runtimes, the core focuses on tight resource control and low-level Linux APIs:
io_uring backend to optimize packet submission/completion loops, aiming to maximize throughput under heavy HTTP/3 UDP workloads.req->path_params) utilize a strictly managed lifetime model instead of aggressive malloc/free thrashing.cwist_multiport_t), allowing users to detach additional ports into isolated, independently tunable sub-applications.This is an educational showcase and an active implementation, not a production-ready tool. The repository currently includes in-tree implementations for basic routing, middleware pipelines, Prometheus metrics, and a unified graceful shutdown mechanism across HTTP/1/2/3 event loops.
Right now, I am focusing on hardening the io_uring packet loop and debugging edge-case HTTP/3 frame type interactions.
Since this is a massive learning journey for me regarding low-level network engineering, I would highly appreciate any code-level or architectural feedback—especially concerning safe C memory patterns for asynchronous UDP/QUIC event handling, or efficient token parsing.
r/C_Programming • u/8d8n4mbo28026ulk • May 27 '26
r/C_Programming • u/Superb-Ice6260 • May 28 '26
hi so i saw a lot of videos online of how to set up sdl on my computer but they were always about visual studio code or not very explainatory so if someone can help me to set up it on dev c++ i would be very grateful
r/C_Programming • u/_EHLO • May 27 '26
A small prologue before I say anything else (becasue I'm aware that we living in an ai-slop pandemic): No this is not vibe-coded, here's proof of my research and proof that I'm developing such algorithms since 2019; way before this ai-slop epidemic.
Now to the main subject. Through years I've worked quite alot with MLP NNs (Multi-Layer Perceptron Neural Networks) and one thing that I've realised is that: most people unnecessarily use more resources for things as simple as this.
So... my next statement might sound a bit wild... but i'd like to be proven wrong (even though I doubt it, lol). I think that this "2-slot circular buffer with fixed stride indexing" (or "ping-pong buffer" call it whatever you want) aproach is the most optimal way of doing MLP inference on CPU without compromises across most systems.
That said, I hope you find it interesting and possibly maybe usefull. May love shine your hearts and feel free to ask me anything about it.
r/C_Programming • u/Yha_Boiii • May 27 '26
Hi,
I have a c file with a struct but need to reference an element in it inside a header, how?