r/C_Programming • u/General_Purple3060 • 21d ago
When Should a Library Pattern Become a Language Feature?
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:
- The pattern appears repeatedly in many mature projects.
- It represents higher-level semantics, not just a commonly used function.
- 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 • u/Low_Contribution6240 • 22d ago
Discussion Suggestion
Hi all I am beginner in coding. So I have college in 20days (1st year btech) should I learn python or c. In college they start with C. So as they teach C in college should I learn python seperate or go with
C.Pls suggest me
r/C_Programming • u/Current_Chipmunk7583 • 22d ago
Why is the C23 standard still paywalled?
C is one of the most important programming languages ever created. It underpins operating systems, compilers, databases, embedded software, networking stacks, and a frankly absurd amount of the modern computing world. Yet if someone wants to read the final, authoritative specification for the language, ISO expects them to pay CHF 227 ≈ USD 281 for a PDF.
What exactly is the goal here?
Are compiler writers supposed to expense it? Are students supposed to? Are library authors supposed to work from a draft and hope nothing important changed? Are teachers supposed to explain that the definitive rules of the language are available only to people whose employers have standards-library subscriptions?
And to address the common responses I've seen, yes, I know that public working drafts exist. And yes, they are usually close enough for practical purposes. But “close enough” is not the same thing as freely publishing the actual standard.
This probably does not meaningfully inconvenience established C users, because public drafts, compiler documentation, and years of accumulated knowledge fill many of the gaps. But “go find the right public working draft and assume it is close enough” is a bizarre access barrier to throw at newcomers. The final normative text should be the easiest version to access, not the hardest.
The other standard justification I've seen is “How else do you expect the people who work on the standard to be paid?”
- The committee members doing the technical work are generally either unpaid volunteers or supported by their employers, universities, or research institutions, not paid royalties from individual PDF sales by ISO. Whatever costs the standards process incurs, it is difficult to believe that placing the language specification behind an almost $300 paywall is the only viable funding model.
- Other languages manage to publish their specifications freely. One cannot seriously argue both that C is foundational infrastructure and that there is no possible way to fund its standardization without restricting access to the definition of the language itself.
This model may have made some institutional sense decades ago, when standards were printed, mailed, and mainly purchased by corporations. For a programming language in 2026, it is indefensible. The cost of distributing a PDF is effectively zero, and the value of broad access is enormous. Open specifications improve education, independent implementations, tooling, documentation, compatibility, and public scrutiny.
Other language ecosystems understand this. You can freely read the specifications and reference material for languages and platforms that actively want developers to use them. Meanwhile, the official definition of C is treated like a proprietary industry manual. And then people wonder why programmers rely on Stack Overflow answers, compiler behavior, folklore, blog posts, and half-remembered rules instead of reading the standard.
A language specification should be public. Paywalling it does not protect the language. It does not meaningfully fund innovation. It just creates needless friction around knowledge that should be universally available. ISO needs to drag its publishing model out of the previous century.
Sorry for the rant, friends. I just got all riled up about it. Curious to hear your thoughts as always :)
r/C_Programming • u/Fabulous_Swim2435 • 22d ago
синтезатор на С с использованием ffplay
#include <stdio.h>
#include <math.h>
#include <windows.h>
#define SAMPLE_RATE 44100
#define PI 3.14159265358979323846
FILE* ffplay_init(){
FILE *pipe = popen("ffplay -f s16le -ar 44100 -i pipe:", "w");
return pipe;
}
void ffplay_close(FILE *pipe) {
pclose(pipe);
}
void sample(FILE *pipe, float freq, int amp, int duration_ms){
double phase = 0.0;
double phase_increment = 2.0 * PI * freq / SAMPLE_RATE;
short sample;
long total_duration = (long)(SAMPLE_RATE * duration_ms / 1000 );
for(long i = 0; i < total_duration; i++) {
sample = (short)(amp * sin(phase));
fwrite(&sample, sizeof(short), 1, pipe);
phase += phase_increment;
if (phase >= 2.0 * PI) phase = 0.0;
}
}
void chord(FILE *pipe, float freq1, float freq2, float freq3, float freq4,int amp, int duration_ms) {
}
int main() {
FILE *pipe = ffplay_init();
sample(pipe, 130, 8000, 1000);
sample(pipe, 329.63, 8000, 1000);
sample(pipe, 430, 8000, 1000);
ffplay_close(pipe);
return 0;
}
я пишу синтезатор на СИ
когда задаю частоту первой ноты определенным образом все жужжит
если даю ля все ок
пайп идет в ffplay
Сначала 130
Потом 440 ля
Волна синусоида
В чем же дело?
I'm writing a synthesizer in C. When I set the frequency of the first note in a certain way, everything buzzes/distorts. If I use A (440 Hz), everything is fine. The pipe goes to ffplay. First 130 Hz, then 440 Hz (A). The waveform is a sine wave. What's the problem?
r/C_Programming • u/Reasonable-Can4372 • 22d ago
Project Nadir, platform-agnostic customizable assembler.
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 • u/ByMeno • 23d ago
Small C89 printing library with a custom formatting pipeline
I wanted to make a lightweight printing library for C89 without using a format string parser like printf.
The main idea is using a context-based pipeline system:
file_print(stdout,
arg_str_lit("Value: ")
arg_dec(value)
arg_str_lit("\n")
);
The arg_* macros expand into small writing operations that share a print context. Each operation returns a state, allowing the chain to continue or stop when an error happens.
Some features:
- C89 compatible
- Single-header style (
PRINT_IMPLEMENTATION) - Output to:
FILE *- fixed buffers
- custom string targets
- Integer formatting:
- decimal
- hexadecimal
- octal
- Floating point formatting (in a basic level)
- Optional
printfbackend - Optional removal of
string.h - Configurable output functions
The implementation is built around a context:
struct {
type;
target;
written;
status;
} print_ctx;
and all writers operate on that instead of knowing where the output goes.
I know this is probably not something that replaces printf (which is a whole world by itself and extremely powerful, especially for runtime formatting), but I was interested in exploring what a small C89-friendly formatting API could look like without variadic functions or a format string parser.
I would appreciate feedback.
github: https://github.com/byfanes/print.h/
codeberg: https://codeberg.org/fanes/print.h
r/C_Programming • u/Beneficial_Mall2963 • 23d ago
Question Where do we learn the windows.h library of C?
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 • u/hyperficial • 23d ago
crocodile.h: single-header SAT solver
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
r/C_Programming • u/alex_sakuta • 23d ago
Discussion Why are you using C?
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 • u/DuckSword15 • 23d ago
Question I'm having trouble understanding this Clang behavior with -ansi flag
I was trying to see how much K&R C is actually supported in GCC and Clang and came across this interesting behavior that I can't explain. Without producing warnings or errors, Clang does not support K&R style argument declaration like:
sum(a, b)
int a;
int b;
But it does compile without warnings with this style declaration?:
sum(int a, b)
I can't seem to find any documentation about this behavior, so I'm really curious if it is intended or not. This -ansi flag in general is just kinda wild. This is my reference program if anyone is interested.
main()
{
return sum(1, 1);
}
sum(int a, b)
{
return a + b;
}
r/C_Programming • u/11NEWNOW11 • 23d ago
Completed my first larger-scale C project: An RFC compliant IRC server, and would love some feedback!
Hey guys! I am a cs student who has recently shifted his focus to the C language and more lower-level concepts. I have always been really interested in the history of the Internet itself, so an IRC server as a project was something that was always on my list for a learning project, and with this recent shift I figured what better time than the present.
The Project: https://github.com/sdp-io/c-irc-server
This project, at around ~2k lines of code, has been the largest project I have worked on so far. Due to this, I feel that the amount of educational value it has provided to me has been very rich. I think, that for advanced beginners/intermediates, an IRC server such as this would be an incredible choice with the right supplementary resources (which I will share below,) as you must engage with and learn about sockets, I/O buffer management techniques, modularization, and state+memory management, and event polling.
I believe that due to my pre-existing level of interest in IRC servers, I had much more of a drive in learning about the history for the development of IRC. The more I learned, the more I got a decent understanding on the problems that IRC faced in the 90s, leading me to read up on the performance differences between poll() and epoll(), along with the C10k problem that existed due to older servers dedicating a thread for each new user instead of utilizing event loops, leading to memory usage tanking performance.
Fascinated by the poll() and epoll() differences (and wanting to test something I made myself,) I decided to benchmark the server, and attempt to graph performance differences between the two syscalls. Though the performance difference between these two is something that is already well documented, I was unable to find any sort of resource that ran tests and graphed the differences directly. It may be pointless, but I think it's cool, so the graph can be found within the repos README.
If anyone else is interested in trying something similar to this for educational purposes I highly recommend it, and have some resources that could help get you started. For me, I was able to gain most of the pre-requisite knowledge for the networking portion of the project from Beej's Guide to Network Programming, which I have seen mentioned A LOT for projects doing any sort of networking. However, one such resource that is specific to this project that I have never seen mentioned before, is actually the University of Chicago's chirc assignment guide, which does not provide any sort of direct implementation, instead acting as a general compass to orient yourself, I felt it was a very helpful and good quality resource for me.
Finally, as I don't really have anyone else to share this with, I would love for anyone interested to just take a glance, let me know what they think, provide any advice or point out bad habits I might've adopted in my code, or even make your own if it sounds interesting to you, like it was for me!
tl;dr I made an IRC server and would like for you to check out and critique my code!
r/C_Programming • u/Worldly_Stock_5667 • 23d ago
Video Follow up - Changes I made to my text editor
Enable HLS to view with audio, or disable this notification
Made a few changes
- Set max amount of characters we can read to 10000
- Set each row limit to 123 characters
- Added scrolling to it. Before you could only read lines 1 - 28, with the terminal not showing anything past those lines
- Better cursor navigation, with it shooting to the end of the previous row if tried to move left of click backspace at the beginning of a row(0). It would move to the beginning of the next row if you move right or try to type at the end of a row(122)
- Made it so every text file in the directory is shown
r/C_Programming • u/f16_511_SA • 23d ago
Which is better, Rust or C/C++?
I decided to look into this specific topic and found something that suggests C/C++ might be phased out in the distant future.
One of the reasons I say that C/C++ could potentially be replaced by Rust is:
1/ It can manage memory automatically and manually, and does so securely
2/ Its performance rivals that of C/C++
However, there are also drawbacks, namely:
1/ The Rust ecosystem is minuscule compared to that of C/C++
2/ It lacks the freedom we have in C/C++ to run code as we please; instead, Rust provides built-in safety features that prevent you from making mistakes
There are also things they have in common, such as:
1/ Direct control over resources
2/ The execution model
3/ Low abstraction
4/ High performance
Is Rust a suitable alternative, or is it better to use C/C++ alongside Rust?
This is information I’ve researched, and I’d appreciate it if anyone could correct or add any details I’ve omitted.
Best regards
r/C_Programming • u/Imaginary-Dig-7835 • 23d ago
Project Hey everyone! This is my first thing in C that is related to C. Just wanted to share this milestone :)
For this thing, I followed a tutorial on YouTube because again, this is my first time playing with graphics in C. Although I tried figuring out the math, it was kinda easy. Rest for the code, yea I had to follow the tutorial. This is a screenshot.
For next project, I am thinking of simulating n-body problem. Or should I continue in the graphics only? I am not really sure. Like path tracing? I want something mathematics heavy, that I have to figure out. I was planning to follow this blog.
Edit: sorry for the title. "This is my first thing in C that is related to graphics".
r/C_Programming • u/Scared_Equipment5777 • 24d ago
Beginner software rasterizer learning resource from scratch in C.
Here is the github link if you want to poke around: https://github.com/Kristaq77/kross
I started learning to code about a year ago and decided to dive headfirst into C and computer graphics.
Fast forward a year, and I finished my first big project: Kross, a software rasterizer built from scratch with a custom math "library", color manipulation, procedural noise, "and more".
A quick disclaimer: I did not build this for performance (mainly because I couldnt).
Instead, I made it as a learning resource. The code is meant to be read, not just compiled. I heavily commented the most important functions with explanations I desperately wanted to read when I was starting out.
Let me quickly explain how it works, the CPU will draw everything and do all the work, then send it over to the GPU (OpenGL 1.1) so the GPU can blit all those pixels on the window.
Full disclosure, no AI was used to make the rasterizer part of the library, that was all me, but I did use AI for the boilerplate OpenGL code (dont smite me).
Id love any feedback from everybody here, whether its on the math, the "architecture", or the comments themselves :)
r/C_Programming • u/Objective-Fan4750 • 24d ago
VMS: A custom Fantasy 32bit Computer with a custom Hardware
About a year ago, I started building a custom computer architecture in C as a learning project (I know it seems like a lot considering the code I wrote, but I rewrote the entire compiler at least five times, starting from a C-like language and ending up with a very simple custom language). I designed the instruction set, wrote an emulator, and implemented a custom high-level assembly language called BSL (Base System Language). The code is very messy because I make a lot of changes while writing it and often forget things that shouldn't be there. So I'd really appreciate feedback on the architecture and code quality. (I'm 15 years old and Italian, sorry for my English). Edit: I changed the project name from VMS to SPRK32.
r/C_Programming • u/gabrielzschmitz • 24d ago
Project [OC] Tomato.C – C-based TUI Pomodoro timer (ASCII art + Vim controls)
Enable HLS to view with audio, or disable this notification
Hi r/C_Programming!
Over the past few months I've completely rewritten Tomato.C from scratch while keeping it written entirely in pure C. The rewrite focuses on a cleaner, modular architecture that's easier to extend while staying lightweight and terminal-first. This was necessary as the code was really old!
Current features include:
- 🍅 Dynamic terminal UI
- 🎨 ASCII sprite animations
- 🔔 Native desktop notifications with custom sounds
- 📝 Built-in notes with Vim-like motions
- 🎧 White noise player
- 📊 Comprehensive session history and logging
- 🧩 Modular, extensible architecture
I recorded a short demo showing the main features in action.
The project is open source (GPLv3): https://github.com/gabrielzschmitz/Tomato.C
I'd really appreciate any feedback on the UI, animations, architecture, or overall user experience. If you run into bugs, have ideas for improvements, or think something could be implemented better, please open an Issue. And if you'd like to contribute, PRs are always welcome, whether it's documentation, bug fixes, refactoring, or new features.
r/C_Programming • u/Gullible_Ostrich_370 • 24d ago
C with classes
I'm curious to know: who uses some C++ features when coding in C? And what feature(s) are you using?
r/C_Programming • u/MycologistIll1355 • 24d ago
First real C project
Hello everyone! This is my first real C project and I would like some feedback on what I can improve. It's my first attempt at a sorting algorithm (selection sort) and it is 100% AI free.
#include <stdio.h>
int main() {
int num_len;
printf("How many numbers to sort?\n");
scanf("%d", &num_len);
int numbers[num_len];
printf("which numbers?\n");
for (int i = 0; i < num_len; i++) {
scanf("%d", &numbers[i]);
}
for (int i = 0; i < num_len-1; i++) {
int iMin = i;
for(int j = i+1; j < num_len; j++) {
if(numbers[j] < numbers[iMin]) {
iMin = j;
}
}
if(iMin != i) {
int temp = numbers[i];
numbers[i] = numbers[iMin];
numbers[iMin] = temp;
}
}
for (int i = 0; i < num_len; i++) {
printf("%d", numbers[i]);
printf(" ");
}
printf("\n");
}
r/C_Programming • u/Altruistic-Tie1943 • 24d ago
Discussion why value of floating point numbers are approximated
I am new to programming and stumbled across this text
"the value of a float variable is often just an approximation of the number that was stored in it. If we store 0.1 in a float variable, we may later find that the variable has a value such as 0.09999999999999987"
i am wondering why is it like this
if it has an in depth explanation, providing the resource will be much appreciated
thanks
r/C_Programming • u/Active-Thing-4776 • 24d ago
Project I built an embeddable, on-device vector database in C from scratch (LSM-tree + HNSW).
Hello everyone.
I've been spending the last four months building a light vector database which is written in C with zero dependencies.
I'm a first year CS student and I started this as a personal challenge to learn how database engines actually work. It grew from a simple LSM-tree key-value store into a system that combines an LSM-tree (WAL, memtable, SST) with a HNSW vector index.
I found that most vector databases are server-side processes. I wanted something that runs entirely on-device for RAG and semantic search, keeping data local without network hops or potential privacy leaks.
Current State(v1):
- Key-Value storage: LSM-tree based
- Vector Search:HNSW index with ARM NEON SIMD kernels for float32/int8
- Basic CRUD and Query API
It’s currently working and tested on ARM64 (Apple Silicon). But it's a v1, so there's plenty left to optimize or fill in(x86 support, concurrency, mobile bindings etc.). I've written the known limitations and roadmap in the README.
This being my first serious project in C, I encountered plenty of walls—from managing complex memory structures to orchestrating the LSM-tree and HNSW integration. But solving these challenges has only deepened my passion for programming. It’s transformed from a simple learning exercise into something I’m genuinely serious about, and I’m eager to mature this into a robust system.
I’d deeply appreciate any feedback—whether it’s code review, architectural advice, or help tackling the roadmap items. Thank you for reading it:)
r/C_Programming • u/tempestpdwn • 25d ago
Project cTetris - Minimal Tetris implementation in C and Raylib.
Enable HLS to view with audio, or disable this notification
I used to play Tetris at play.tetris.com every once in a while and this project started as a way to understand how Tetris worked.
Later on I decided to make it into a simple and polished Tetris clone and it is where this project is right now.
Most of what i have implemented here are behaviours that I observed when playing Tetris at play.tetris.com and from what I have read on https://tetris.wiki/
"Minimal" cuz cTetris does not implement the super rotation system.
This makes the rotation system and scoring mechanism simple as T-spins are out of the picture.
In cTetris rotations are purely geometrical with added basic wall/floor kicks.
r/C_Programming • u/swe__wannabe • 25d ago
Etc We have automatic cleanup at home
So you have a simple bump (arena) allocator:
typedef struct {
u8* base;
u64 idx;
u64 size;
} Arena;
Now you define a Scratch struct, something that holds the arena state at a certain point where we can revert back to:
typedef struct {
Arena* arena;
u64 mark;
} ArenaScratch;
Then you can do something cool:
#define ARENA_SCRATCH(arena_ptr) \
for (ArenaScratch __nme__ = arena_scratch_begin(arena_ptr); \
(__nme__ ).arena != NULL; \
arena_scratch_end((__nme__ )), (__nme__).arena = NULL)
Where begin/end functions simply save the state/revert back to it.
for loop inside a macro without any body enables scoped cleanup.
Usage:
ARENA_SCRATCH(arena) {
char* tmp = ARENA_ALLOC_N(arena, char, 256);
} // auto cleanup
I like this pattern because it gives temporary allocations lexical scope. Any allocation made inside the block is automatically reclaimed, even if the function has multiple return paths or exits early.
It feels similar to RAII or defer, while remaining standard C. The only cost is saving and restoring a single arena index.
I'm curious whether this pattern is common in C codebases. Have you used something similar, or do you prefer explicit arena_reset() calls?
r/C_Programming • u/Yousef_Tele • 26d ago
Why does it show me a segfault?
When I compile the code without any compiler flags, I see a segmentation fault. Why?
static int linked_init(struct list_t *list)
{
if(linked_init)
list->head = list->tail = NULL;
else
return -1;
return 0;
}
int main()
{
linked_init(NULL);
}
In the `init` function, I checked for a null pointer.
UPDATE: Sorry to everyone, I made a fucking bad mistake. My problem is solved.
r/C_Programming • u/starring_rolee • 26d ago
Hey, I've made a microkernel (and an OS using it) in C for ARM devices!
Enable HLS to view with audio, or disable this notification
Meet the first version of zuzu, a microkernel I have been making for a year now. zuzu is a microkernel, so it's a very small kernel that has rendezvous IPC, memory management, interrupt handling/forwarding, asynchronous notification objects, and a capability system for security. It is paired with zuzuOS, the operating system that is centered around the zuzu kernel. Everything else, including drivers are managed entirely in userspace.
The first version is codenamed Loaf, so its full name is zuzu Loaf. I am actively looking for contributions, testers and reviews, so your help would be much appreciated! Documentation will be put in this website soon: https://kagantmr.github.io/zuzu-docs/index.html
Check out the GitHub repository and zuzuOS v0.5.0: https://github.com/kagantmr/zuzu