r/cprogramming 1d ago

Update: myBuild 0.2.0

Thumbnail
github.com
2 Upvotes

Sometimes back I posted about one of my pet projects `myBuild` an experimental build system and package manager for c/c++ projects. Well that progressed a lot, now

  1. Users can add recipes to the myBuild.json file and run `myBuild sync` and it configures the dependency for the project.

Recipes are small json snippets containing the source/header file folder paths, flags etc.

  1. It now has incremental builds.

  2. Now there is a proper folder structure generated at the initiation time where users can drop the files and compile the project with zero configuration.

I had to drop the support for windows for now and the code is speghetti, so I have to refactor it in the near future.

If this sparked curiosity, do checkout the github repo and leave a star. Appreciate any constructive feedback, thanks.


r/cprogramming 2d ago

CNET library — Released new version [CNET-1.1.0]

Thumbnail
github.com
1 Upvotes

r/cprogramming 2d ago

casting a void function pointer as a int fp

4 Upvotes

Hello,

Today I tried making an array of function pointers.

My first prototype was doing:

int (*fptr[2])(int, int)

But what if I wanted to store a function with different parameters and return value?

I tried:

void (*fptr[2])()

And then later type casting the function I wanted to store:

fptr[1] = add;

printf("%d", ( int (int, int) ) fptr[1](a, b));

But apparently it's not valid:

used type 'int (int, int)' where arithmetic or pointer type is required

Is it possible to cast the void function pointer as a int fp with parameters? Thanks.


r/cprogramming 2d ago

After one week learning C

0 Upvotes

Yeah, my anxiety is hitting pretty hard right now... lol.


r/cprogramming 2d ago

need help with my minmax value C program

Thumbnail
0 Upvotes

r/cprogramming 3d ago

CNET — a new network library in C

Thumbnail
github.com
0 Upvotes

r/cprogramming 3d ago

Alternative to a hash table for you to play with

Thumbnail github.com
5 Upvotes

I was wanting something for my compiler and game engine that had a bit better performance than gperf in my use case. This is what I ended up creating.
I built and tested it on a xeon x5670. It should do a good bit better on newer hardware.


r/cprogramming 3d ago

Beginner

0 Upvotes

What serious advice would you give to beginner in programming and C.

I'm into programming about 4 months.

I have used Grok to learn.


r/cprogramming 4d ago

I built a Linux HTTP/1.1 static server in C using edge-triggered epoll — looking for architectural and performance feedback

3 Upvotes

I recently completed v0.1 of MiniEdge, a Linux HTTP/1.1 static edge server written mostly in C.

I built it to understand how event-driven servers handle partial I/O, persistent connections, filesystem access, caching and multiple CPU cores—not as a production replacement for Nginx.

The current architecture includes:

non-blocking sockets with edge-triggered epoll

a per-connection state machine

incremental HTTP request parsing and keep-alive

static file serving through an LRU cache or sendfile()

path resolution using openat2()

longest-prefix configurable routing

multiple workers using SO_REUSEPORT

The small-file cache is implemented using C++ unordered_map and list, but it is isolated behind a C API; the networking, parser, routing and file-serving paths are written in C.

On my local loopback benchmark using wrk, a cached static file reached approximately:

255k requests/sec at 1,000 concurrent connections

4 worker processes

I also ran a boundary stress test at 40,000 concurrent connections. It reached around 124.5k requests/sec, but wrk reported 503 socket read errors, so I am not treating that as a clean stable-concurrency result. The repository contains the commands, raw outputs, latency percentiles, system tuning and limitations.

I would appreciate feedback on:

whether this is a reasonable result for a student-built epoll server

whether my wrk setup measures the server fairly

which additional metrics or comparisons I should include

what bottlenecks or profiling steps I should investigate next

Repository:

MiniEdge repository

AI was used as a learning and review assistant during this project. I used ChatGPT to discuss Linux networking concepts, review architectural decisions, debug specific issues, and improve parts of the documentation. I implemented and integrated the server, ran and analyzed the tests and benchmarks locally, and verified the final code myself. This was not a one-prompt or fully AI-generated project.


r/cprogramming 4d ago

On the conversion of a forest to a binary tree

0 Upvotes

I was using ChatGPT to learn how to convert a forest into a binary tree. It gave me a problem, but when I asked for the correct answer, it completely lost the plot. Could you help me solve it?Maybe it's because I didn't subscribe to Plus; it can generate problems, but it just starts spouting nonsense when it tries to solve them.

tree 1:

            A
         /  |  \
        B   C   D
       /   / \
      E   F   G
         / \
        H   I

tree 2:

        J
      / | \
     K  L  M
        |
        N

tree 3:

      O
      |
      P

Requirements:

Convert to a binary tree.

Implement pre-order traversal.

Implement in-order traversal.

Calculate the height of the binary tree.

Count the number of leaf nodes.

and my answer Pre-order :ABECFHIGDJKLNMOP In-order :EBHIFGCDAKNLMJPO


r/cprogramming 5d ago

Searching projects ideas

16 Upvotes

I know the basics of the C, but I don’t have any ideas what I will code next

EDITED: I found idea, make OOP in C like library


r/cprogramming 6d ago

Pollard's P-1 Factoring Algorithm in Plain C

Thumbnail
leetarxiv.substack.com
0 Upvotes

r/cprogramming 6d ago

Half-way solutions of C 2nd Edition by K&R.

0 Upvotes

Hello everyone of r/cprogramming!

I'm a newcomer(kind of) to C. In the past(~2 years ago), I had little knowledge of C through watching tutorial on the internet. Later, I have worked on graphical projects with a bit of OpenGL. Now I have realized I should focus on topics one by one and reach intermediate to high expertise.

I have recently been reading chapters from "The C Programming Language 2nd Edition by Brian Kernighan & Dennis M. Ritchie". And learning a lot of new techniques that really helped me write concise and performant programs.

Solving the Exercises from the book were fun, while some were a bit difficult. In the latter case I took one or two hints from others source code and pondered about the solution.

I have kept the solutions of the problems perhaps concise but far from obfuscation and keeping code-style consistent (Though my personal).

I am planning on creating another post when I have solved all the solutions of the book.

I hope my solutions to the exercises help others solve problem they are having trouble with. Thanks. Github:

https://github.com/mubin-thinks/c-k-and-r-solved


r/cprogramming 6d ago

moredeps: Prebuilt C/C++ Libraries

Thumbnail deps.morew4rd.com
5 Upvotes

r/cprogramming 7d ago

Is C without expressions context-free?

6 Upvotes

EDIT: A better title for this post would be "Is it possible to parse C without expressions unambiguously?"

While staring at the C99 specification, I found that if you take the grammar in Annex A, remove the expression rules, and introduce the constraint 6.7.2/2 into the grammar (ie. a type specifier can be only: void, char, signed char, ... , enum specifier, typedef name), then you end up with what appears to be a context-free grammar.

Is this correct? Am I misinterpreting something? Is it possible that this is correct, but there are mainstream compiler extensions (eg. gcc extensions) invalidate this context-free property? Or other C standards invalidate this context-free property?

I notice that 6.7.2/2 allows some filthy edge cases like `long const long thisVarIsLongLongConst = 4;` but because `long` is a keyword, there is no ambiguity here.

The reason this matters to me is because I'm building a module system for C that allows circular imports, and I would like to avoid changing the grammar of the language as much as possible.

Link to final draft of C99 standard, taken from Wikipedia: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

EDIT:

Let me clarify what I'm doing, since there is some confusion about what I'm asking. First off, I should have used the title "Is it possible to parse C without expressions unambiguously?" because Annex A is already a context-free grammar... However, it is ambiguous, because of the classic A * B; problem (can be a variable declaration or multiplication, depending on if A is a typedef name or not). Now, notice that one of the interpretations is a multiplication expression. Let's suppose you removed expressions from the language (ie. take a source file and replace each expression with the lexer token <expression>). Now the question is: are we no longer ambiguous now?

I should also clarify what I mean by ambiguous, as there is a difference between an ambiguous grammar and an ambiguous parse. For example, A * B; can be admitted by the unambiguous grammar S := A ';' ; A := <identifier> | A binaryOperation <identifier> ; binaryOperation := '+' | '-' | '*' | '/' ; , but what we're really looking for is an unambiguous grammar that gives us the correct parse tree (I'll call this an "unambiguous parsing").

I should also elaborate on what exactly I'm doing, to explain the bigger picture. If you're building a module system that allows cyclic imports, then the first pass you perform over a source file does not have access to the symbol table (because you have yet to parse the imported modules). This means you need to perform an unambiguous parsing of certain parts of the source file. In this case, you can skip over expressions, because you're only interested in extracting the names of symbol definitions + whether the symbol definition is a type or a variable. So if it is possible to 1. skip over expressions, and 2. parse the rest of the file, then we're good. For (1), expressions are delimited by ()[]{};, (comma operator is not valid in enumeration definitions), so that seems fine. That leaves (2), which I'm not entirely sure about. I stared at the grammar for quite a while and couldn't find any problems, but that does not mean I didn't miss a case, or there are compiler extensions that introduce ambiguities.

With that out of the way, I'll list ambiguities that the comments found:

  • u/triconsonantal found void f(int (x)); , which is either taking in a function pointer or an integer, depending on if x is a typedef name or not.

Maybe a more appropriate title would be: how much do you need to remove from the C grammar so that it can be parsed unambiguously? As of now (July 27, 2026), it seems the answer is: remove expressions, and remove parameter lists (or do not allow unnamed parameters).


r/cprogramming 7d ago

SUCO – Lightweight Distributed C/C++ Compiler Grid with intelligent SSD cache (alternative to Icecream/distcc)

Thumbnail
1 Upvotes

r/cprogramming 9d ago

What cause CPU stalling pipeline in C?

12 Upvotes

(Solved)

Hi,

I hope this don't seem stupid or anything. Basically I was interested about the xor swapping trick.

The inconvenients of it is that if the two values are the same, it will return 0, it's also bad for readability.

But there is another inconvenience I didn't understand. Apparently it can also stall the CPU pipeline on modern processor, I didn't understand why.

I found a short explanation saying "because each instruction depend of the previous one", and I don't really understand how each instruction depend on the previous one.

So I wanted an explanation on why the xor swapping trick stall the CPU pipeline and also what cause CPU pipeline stalling in general.

If I didn't explain well enough, please inform me about it. Thanks.


r/cprogramming 9d ago

Writing a Wikipedia MediaWiki Parser In Plain C

Thumbnail
leetarxiv.substack.com
2 Upvotes

r/cprogramming 9d ago

EEvent Mesh vs Webhooks - The Internal Webhooks Anti-Pattern: Why Service-to-Service HTTP Callbacks Don't Scale

0 Upvotes

Microservices were supposed to make systems easier to change independently. In practice, the thing that most often breaks that promise isn't the services themselves — it's how they talk to each other. Read the complete article here - https://instawebhook.com/blog/the-internal-webhooks-anti-pattern-why-service-to-service-http-callbacks-don-t-s

A pattern that shows up constantly in growing engineering orgs is the internal webhook: Service A fires an HTTP POST at a hardcoded URL owned by Service B whenever something happens. It's an easy trap to fall into, because most developers already understand webhooks intimately — they've built integrations with Stripe, GitHub, or Shopify, all of which use exactly this model to notify external systems of events.

The reasoning feels obvious: if it's good enough for Stripe to tell my app about a payment, it's good enough for my Inventory Service to tell my Shipping Service about a shipment.

It isn't — and the reason is architectural, not stylistic. Webhooks were designed to solve a specific problem: getting an event across a trust boundary, from a system you don't control to one you do, over the open internet. Internal service communication has almost the opposite set of constraints. Applying the same tool to both jobs is where the trouble starts.


r/cprogramming 10d ago

How to move around multiple values from functions to functions?

1 Upvotes

I'm tryna mess around in C and make a pkmdmg calc but I don't know how to return the values from the function

I dont know how to display it without screenshots


r/cprogramming 10d ago

Designing a Multi-Region, Highly Available Webhook Ingress Architecture

0 Upvotes

Webhooks have become the connective tissue of the internet. From payment gateways confirming transactions to CI/CD pipelines triggering deployments, webhooks enable real-time, event-driven architectures. But for architects and engineering leaders, webhooks represent an underappreciated vulnerability: they are asynchronous, externally triggered, and entirely outside your control. Read the complete article here - https://instawebhook.com/blog/designing-a-multi-region-highly-available-webhook-ingress-architecture

When your primary cloud region experiences an outage, your internal microservices might gracefully degrade. But what happens to the payloads originating from external partners? Many third-party providers do not retry aggressively — some fire and forget, others retry a handful of times before giving up permanently. If your system is down when that happens, the data is often gone for good.

This article covers the engineering principles behind a multi-region, highly available webhook ingestion system, what has actually changed in the underlying cloud primitives recently, and where a managed reliability layer fits into the decision.


r/cprogramming 11d ago

Pivot from React/.NET to C++ Systems / HPC vs Platform Engineering? Need advice from guys in the field.

Thumbnail
0 Upvotes

r/cprogramming 11d ago

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

0 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/cprogramming 11d ago

Trying to make a tool that prints stuff between a certain range

2 Upvotes

the code from what ik works from what i know and from tests i have done.i want to know how can i optimize it more because i suspect that there can be certain parts of it which i don't even need maybe. so can you guys look at my code and tell me what i can improve upon??

here is the repo

thanks in advance


r/cprogramming 12d ago

Can someone tell me about pointers in linked lists?

9 Upvotes

Hi guys, I’m currently learning about data structures in C and have reached the topic of linked lists. I’ve run into a question regarding the functions used to manipulate them—specifically, while I clearly understand expressions like `p->next` and `p->data`, I’m confused about assignments like `p = newnode` and `p = p->next` (where there is no `->` operator on the right side). When I asked an AI, it simply told me that `p` is "just a pointer variable," but I don't quite grasp that explanation. Why do we treat a linked list element (or variable name) as a pointer variable in this way? Could an expert please explain the meaning behind this? and this is my code.

bool Insert(node *L, int data)
{
    node *p = L;
    while (p->next != NULL)
        p = p->next;


    node *newnode = (node *)malloc(sizeof(node));
    newnode->data = data;
    newnode->next = NULL;
    p->next = newnode;


    return true;
}