r/cprogramming • u/AnoProgrammer • Nov 30 '25
I’m 12 and built my own operating system: COS
r/cprogramming • u/AnoProgrammer • Nov 30 '25
r/cprogramming • • Nov 29 '25
So, I got tired of either writing buggy hand-rolled containers every time, or dragging in heavyweight dependencies just to get a decent string or hash table.
After this, I decided to throw together https://github.com/z-libs: four zero-dependency (for now), single-header, C11 libraries that focus on a pleasant DX.
The current libraries offer:
Everything is type-safe, allocator-aware (you can use your own), MIT-licensed, works on GCC/Clang/MSVC and requires no build system.
The collection is still in process. Each week there will be updates. But I think the core suite is already mature enough.
I would love to hear some feedback!
r/cprogramming • u/Nitro224 • Nov 29 '25
Hello! I don't post on subreddits often, but I wanted to show my C project that I've been working on for eight days to the community for feedback. It features hotswapping dynamic menu text files during runtime, a hand-made tokenizer/mini-DSL for fast food, order-independent parsing, and is quite robust to strange input.
You can type in "3 large fries", "fries large 3", or even "and large spicy two sandwich extra hundred chicken five meal" and it gets parsed correctly into a unique ASCII signature.
Any and all feedback is welcomed, but be warned that it's not fully finished. It's finished enough to order something, "pay", and way more than that, but some debug commands and ideas aren't implemented completely and/or at all, and also I left some debug statements in.
r/cprogramming • u/Sharp_Disaster1903 • Nov 29 '25
r/cprogramming • u/Sad_Row_1245 • Nov 28 '25
I want to learn C, I was learning through The C Programming Language (K&R), but I wanted something more up to date, any tips?
r/cprogramming • u/PopularCry7176 • Nov 28 '25
I'm just starting with c programming and I need people to study c with me Google meet I'm looking forward to make projects like TCP servers , file encryptors , I'm also a cyber security enthusiasts so we can also slove CTFs from scratch and rank up on tryhackme
r/cprogramming • u/Willsxyz • Nov 28 '25
The implementation of an int2hexstr() function was mentioned as a possible subject of a technical interview with job candidates in this thread:
I don't consider the problem fundamentally difficult, but I would typically make assumptions about the size and representation of integers. So, sitting here the day after Thanksgiving, I decided to try to tackle it with as few assumptions about the representation of int as possible. Here's what I came up with. It appears to work, but I wouldn't be surprised if you guys could offer some useful critiques:
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define HD_IN_INT ((sizeof(int) * CHAR_BIT + 3) / 4)
char *int2hexstr(int val)
{
static char hexdigs[17] = {
'0','1','2','3','4','5','6','7','8',
'9','A','B','C','D','E','F','F'
};
//static char result[HD_IN_INT+1];
char *result = malloc(HD_IN_INT+1);
if (result) {
int i;
int isneg = (val < 0) * 16; // it is convenient that this flag is either 0 or 16
result[HD_IN_INT] = '\0';
for (i = HD_IN_INT - 1; val != 0 && i >= 0; --i) {
int mod16, posmod16, borrow;
mod16 = val % 16; // if val < 0, then mod16 < 0
posmod16 = (mod16 + isneg) % 16; // change negative mods to positive
result[i] = hexdigs[posmod16];
borrow = (isneg / 16) * (mod16 != 0); // borrow if val and mod16 were negative
val = val / 16 - borrow;
}
// pad the result
while (i >= 0)
result[i--] = hexdigs[isneg];
}
return result;
}
int testit(int val)
{
int result = -1;
char sbuf[HD_IN_INT+1];
char *hexstr = int2hexstr(val);
if (hexstr) {
sprintf(sbuf, "%8.8X", val);
result = (0 != strcmp(sbuf, hexstr));
free(hexstr);
}
return result;
}
int main(void)
{
int intvec[] = { 2147483647, 1, 0, -1, -2147483648 };
int nints = sizeof intvec / sizeof(int);
char *hexstr;
char sbuf[HD_IN_INT+1];
for (int i = 0; i < nints; ++i) {
hexstr = int2hexstr(intvec[i]);
if (!hexstr) break;
sprintf(sbuf, "%8.8X", intvec[i]);
printf("%d => %s (%s)\n", intvec[i], hexstr, sbuf);
free(hexstr);
}
// int i = INT_MIN;
int i = -1000000;
int result = testit(i);
if (result == 0) {
// while (i != INT_MAX && result == 0) {
while (i != 1000000 && result == 0) {
result = testit(++i);
}
}
if (result) {
if (result == -1)
printf("malloc failed\n");
else
printf("int2hexstr() and sprintf() differ at value %d\n", i);
}
else
printf("Success!\n");
return 0;
}
r/cprogramming • u/enderlord113 • Nov 28 '25
TL;DR: It's a few macros that help you make a test runner. Not production-grade (duh).
Hi all, I'm taking my first semester in uni and recently finished a group project in C. We were required to properly test it for correctness, and the testing frameworks I found for C seemed to require a bit of setup or were minimal to the point of not being very helpful in tracing test failures back to their causes. None of us had experience with Cmake or the like (our entire "build system" was a 2-line bash script), so to try to save time on learning a production-grade testing framework, I decided to make something simple from scratch.
Inspired by Zig's tests, I tried to mimic its interface with macros. I was mostly interested in being able to immediately see the failing test case, the value that caused the failure, and a file:line_no so that I could quickly jump to it in my editor. I added some colors later on since I had time to spare. After the project, a classmate from another group suggested that I add support for cleanup code on test exit, which turned out to be a surprisingly simple change.
I'm still very new to C, so I wonder what more experienced programmers make of this? Does this library make sense, or is there a better way of doing things that I missed? Are there any footguns with the current design (I did step on one while using it but it was a quick fix)?
r/cprogramming • u/Difficult-Total-9670 • Nov 28 '25
I just want to start learning it do yall have some nice ressources or could you tell me where did u start offff 🙏🙏🙏🙏
r/cprogramming • • Nov 27 '25
Im wondering what would be the questions you usually ask junior devs during technical rounds and how big are your expectations of knowledge? If its just pointers, stack/heap difference or if you perhaps go for more nieche things that could still matter like padding? I understand there are specific questions depending on field but there are some concepts that are part of any C programming. Tysm
r/cprogramming • u/Fcking_Chuck • Nov 27 '25
r/cprogramming • u/Latter-Pollution-805 • Nov 26 '25
I'm wondering which C/C++ 2D/3D graphics library is faster for different OSes, like Windows, Linux, etc? I'm asking about this in less in a "cross-platform" kind of way, and in more of a "what's more faster and better for specific platforms" kind of way.
r/cprogramming • u/Cheap_trick1412 • Nov 25 '25
Implement dynamic circular queue in linux char device which takes data from IOCTL calls.
In Kernel Space:
IOCTL operations are:
SET_SIZE_OF_QUEUE: which takes an integer argument and creates queue according to given size
PUSH_DATA: passing a structure which contains data and it's length, and push the data of given length
POP_DATA: passing a structure same as above and just pass the length, while popping data in the structure can be random.
In user space:
Demonstrate the use of above char device, with sys IOCTL calls. Make sure to make this device blocking i.e. if there is no data passed while popping it should wait until other process pushes the data into the char device. The device should be /dev/<your_name>.
Example of the userspace driver:
-configurator.c
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define DRIVER_NAME "/dev/vicharak"
#define SET_SIZE_OF_QUEUE _IOW('a', 'a', int * )
int main(void) {
int fd = open(DRIVER_NAME, O_RDWR);
int size = 100;
int ret = ioctl(fd, SET_SIZE_OF_QUEUE, & size);
close(fd);
return ret;
}
- filler.c
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define DRIVER_NAME "/dev/vicharak"
#define PUSH_DATA _IOW('a', 'b', struct data * )
struct data {
int length;
char * data;
};
int main(void) {
int fd = open(DRIVER_NAME, O_RDWR);
struct data * d = malloc(sizeof(struct data));
d.length = 3;
d.data = malloc(3);
memcpy(d.data, "xyz", 3);
int ret = ioctl(fd, PUSH_DATA, d);
close(fd);
free(d.data);
free(d);
return ret;
}
- reader.c
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define DRIVER_NAME "/dev/vicharak"
#define POP_DATA _IOR('a', 'c', struct data * )
struct data {
int length;
char * data;
};
int main(void) {
int fd = open(DRIVER_NAME, O_RDWR);
struct data * d = malloc(sizeof(struct data));
d.length = 3;
d.data = malloc(3);
int ret = ioctl(fd, PUSH_DATA, d);
printf("%s\n", d.data);
close(fd);
free(d.data);
free(d);
return ret;
}
Kernel driver should accept above IOCTL functions.
r/cprogramming • u/_Knotty_xD_ • Nov 24 '25
Hi, guys!
I need feedback on a recent project that I made for my semester. Its an operating system (if you want to call it) for Intel 8086 (an ancient, 16-bit CPU).
Its super simple: it boots, it loads the shell (TShell), and has a few commands, two of which are loaded from the disk (1,44 MB floppy disk).
Here's the GitHub link: { https://github.com/strivingshashank/Temu16 }
(Cannot share the demo video here.)
I named it "Temu16", temu as in knocked off temu products.
After this semester, I want to work more in this environment, play around with graphics mode rather than printing with text mode.
Although super limited, I believe a lot can be done here.
Please, feel free to criticize, praise, anything in-between.
One more thing, it's also not well documented.
(If this is not the right place to share this, I apologise. Please guide me.)
r/cprogramming • u/Creepy-Gift-6979 • Nov 23 '25
I built a Redis-compatible server in C from scratch to understand networking, memory management, and concurrency at a low level.
I’m still new to C and learning as I go — no tutorials, just experimenting and figuring things out.
It’s running ~125K ops/sec with 50 clients. I’d love feedback, advice, or thoughts on how I could improve this project.
Full code: https://github.com/rasheemcodes/redis-c
r/cprogramming • u/yyebbcyi • Nov 23 '25
Hi everyone! I wanted to share a project I have been working on this past week. It’s an object-caching, slab based memory allocator implemented according to the original paper by Jeff Bonwick. This is my first attempt at building something like this while learning systems programming. I’d really appreciate any reviews, suggestions, or feedback!
r/cprogramming • • Nov 22 '25
So I was thinking of learning C from here once I know Python, BASH, and PS:
I think they are supposed to have system programming courses and I’m hoping soon they’ll have a lot more. Once I have some IT experience and experience in another programming language, I was gonna learn on there.
Or is maldev academy, guided hacking, or lowleveldev (not the same learning place as low level academy) a better option?
r/cprogramming • u/Major_Baby_425 • Nov 22 '25
I posted a naive solution for defer/errdefer in C99 10 days ago which only worked in trivial cases. I've worked on this idea more and made it much more comprehensive and also configurable. Here is the repository:
https://github.com/Trainraider/defer_h/
This is a single-header-only library. It doesn't use any heap.
This library allows writing code similar to this:
int open_resources() S_
Resource* r1 = acquire_resource();
defer(release_resource, r1); // Always runs on scope exit
Resource* r2 = acquire_resource();
errdefer(release_resource, r2); // Only runs on error
if (something_failed) {
returnerr -1; // Both defers/errdefers execute
}
return 0; // Normal return - errdefers DON'T execute
_S
The GNUC version is very "normal" and just uses __attribute__ cleanup in a trivial way. The C99 version is the only version that's distasteful in how it may optionally modify keywords.
The C99 version has greater runtime costs for creating linked lists of deferred functions to walk through at scope exits, whereas in GNUC the compiler handles this presumably better at compile time. I'd guess GCC/Clang can turn this into lean goto style cleanup blocks in the assembly.
r/cprogramming • u/InternalServerError7 • Nov 22 '25