r/C_Programming • • Mar 12 '26

Project Zero malloc after init: web server with a single static arena, binary trie router, and mmap'd asset bundle — 68KB, runs on Pentium III

Thumbnail
github.com
0 Upvotes

The interesting constraints that shaped the design:

Memory: Single flat arena in BSS — 4MB, zero-initialized, allocated once. After main() initialization there are zero calls to malloc or free. Fragmentation is impossible by construction.

Routing: Binary trie built at compile time from the directory structure. O(depth) lookup, 1-3 pointer chases per request. No hash table, no strcmp loops.

Assets: Everything brotli-compressed at level 11 ahead of time, packed into a .web bundle, mmap()'d at startup. Zero file I/O during requests — the OS page cache handles everything.

Concurrency: No threads, no mutexes. Single event loop (epoll on Linux, IOCP on Windows). Under overload it sends 503 and closes immediately — no queue, no accumulated state, no crash.

C99 only. Compiles clean with -Wall -Wextra -Wpedantic -Werror.


r/C_Programming • • May 06 '26

Everyone here said that my website looked like slop, so i spent the night redesigning it!

0 Upvotes

Due to your feedback, I radically changed the design of my website. Because it is a recreational coding platform, I adopted this arcade-y aesthetic.

For those who didn't see my original post, it contains systems-level coding problems in C.

Link: https://elitecode.pro


r/C_Programming • • Apr 29 '26

TRiP: 15,000 lines of C implementing a complete transformer AI engine from scratch

0 Upvotes

I'm a firmware engineer (17 years in embedded systems). Over the past 18 months I built a complete transformer engine in C: inference, training with full backpropagation, BPE tokenizer, chat, and vision; no ML frameworks, no Python; just C, libjpeg, and X11.

Things of interest:

- bf16/f16/f32 mixed precision with manual casting

- mmap-based weight loading for running large models on limited RAM

- the whole thing compiles with a 10-line Makefile: gcc, -Ofast, -fopenmp

It loads and runs real models (Gemma, Llama 2, GPT-2, PaliGemma) from standard HuggingFace checkpoint formats. The purpose is educational; I built it to understand transformers at the lowest level, and structured the code to be readable: every math operation has its forward and backward implementation side by side.

GitHub: https://github.com/carlovalenti/TRiP


r/C_Programming • • Nov 27 '22

Question Why doesn't C implement its own version of object-orientation?

0 Upvotes

Why doesn't C implement its own version of object-orientation?

Why do we have to look at C++, D or something?

Or can we still say that it does?

https://www.cs.rit.edu/%7Eats/books/ooc.pdf


r/C_Programming • • Aug 03 '21

Discussion Why the hell the C programing language doesn’t get the credit and the hype it deserves??

0 Upvotes

In today’s programmers generation I see so much credit and hype on Rust, Python, Go and JavaScript. But I have never seen C is mentioned. I just started to fucking think that they treat their loved high programming language as a black box, without actually knowing that in the end it’s likely to be based on C, or maybe it’s compiler is written in C, or it’s syntax is inspired from C, or maybe it’s a fucking C derivatives language.

It really makes me upset to see that most of this programmers generation not giving C much of an interest.

Edit: Some of you may have understood me wrong. I’m not complaining about the other high level languages. Every language has it’s purpose and a reason why it was developed and created. On the other hand, what I’m trying to say is that C isn’t getting much credit nor interests from the new generation of programmers, whereas C runs the world in one way or another.


r/C_Programming • • May 28 '24

Discussion using object oriented programming on C is beautiful

0 Upvotes

the first time i read somewhere that i could use oop in c, i jumped from my desk and started reading and i found that it was far more intuitive and logic than any other "oop native" language i don't knowe it felt natural respect to other langauge. did you have the same experience?


r/C_Programming • • May 12 '26

I'm so close to bowing my head and starting with Python

9 Upvotes

I haven't even made it past the first half of the first chapter in "The C Programming Language, 2nd edition - Kernighan, Ritchie" and I'm noticing deficits in my math. Maybe I'm trying way too hard on things that don't really matter? I don't even know whats supposed to matter besides this one exercise. The exercise I'm stuck on is converting the Fahrenheit to Celsius formula to Celsius to Fahrenheit. It's not even the coding part I'm stuck on which is frustrating.

I don't think it really matters but I followed the bro code course and got up to nested loops like a year ago then gave up until about last week. I got another book "Math for Programmers: 3D graphics, machine learning, and simulations with Python - Paul Orland" but I want to learn C. Am I backsliding? Am I just too low iq?


r/C_Programming • • Mar 17 '26

I’m building a C compiler in C with a unique "Indexed Linking" system. What do you think of this CLI syntax?

0 Upvotes

I’m working on a hobby C compiler written in C and I decided to go with a pretty non-traditional approach for linking and path management.

Instead of the usual mess of -L, -I, and -l flags where the compiler just "guesses" which header goes with which binary based on search order, I’ve implemented Indexed Environment Mapping.

The Approach: You define a "package" (directory, library file, and include path) at a specific index, and then explicitly tell the compiler to link that index.

Example: Mapping and linking a local libc

./icc "main.c, -s:0={dir:"usr/lib"; file:"libc.a"; inc:"usr/include"}, -L:0, -o my_program,"

How it works:

  • -s:0={...}: This creates a "Source Object" at index 0. It groups the library directory, the specific .a file, and the include directory together.

  • -L:0: This is the trigger. It tells the compiler: "Use the paths and the library defined at index 0 for this compilation unit."

any suggestions are welcome

i'd remove this " " around the command as I get some time


r/C_Programming • • Mar 01 '26

Question Booleans not Working, can someone make sense of this?

0 Upvotes

Although this clip only shows the debugger, this is an issue outside of the debugger too as this code path still executes even though the other two values in the if statement result it false.

This is the Makefile used for the project, in the top right you can see the debug make is being run.

I really do not understand what is going on here, I've never seen on issue like this with anything C related.

Edit: I made a branch for the most recent changes

Edit: I found the issue. ->StructType is a type in a union and the underlying data was not that type. It seems that the not operator only flips the lowest byte and that bool is more than 1 bit wide so that was causing issues with the not operation. I only noticed after trying to confirm that a bool only took up one bit by adding a bit field of 1 on the boolean and getting false.


r/C_Programming • • Mar 08 '24

Question ELI5: Void in C

3 Upvotes

I just began studying C and I cannot, for the life of me, understand void.

I have read and listened to many people say "It does not return a value". Ok? What is a value? Why wouldn't we want to return it? What is the difference between "void main" and "int main"? Can we just use int for everything and ignore void altogether?

In what situations is void used? In what situations is void better? etc. Please help I don't get it at all!


r/C_Programming • • Apr 12 '15

Etc Google agrees too :-)

0 Upvotes

r/C_Programming • • Oct 25 '25

Question How can I make money online with C language?

0 Upvotes

Hi everyone,
I honestly don’t know how I can make money using the C language. I’m studying computer engineering, so I have to learn it — but I actually enjoy it a lot.

I really want to make money online by coding. I’ve tried learning different languages because most online opportunities don’t seem to use C, but it’s still the one I’m most comfortable and confident with.

Right now I’m thinking about maybe creating some apps or tools to sell on Gumroad or similar platforms, but I don’t really have any ideas yet on what exactly I could make. Any suggestions or advice would be super helpful. Thanks!


r/C_Programming • • Apr 07 '24

Article Object-Oriented C: A Primer

Thumbnail aartaka.me
0 Upvotes

r/C_Programming • • Oct 01 '24

Why should I learn C?

0 Upvotes

Hey guys, I learnt JavaScript and python. Python was in my first semester, so I had to learn it to pass and it was easy to understand. And I am learning JavaScript from a web development course. I am not very good in any of them. Just in between basic and Intermediate level. And then I got suggestions from some YouTuber to learn C. Then I started learning C. Now, for me it seems similar to the languages I learnt before. Just syntax are different and some changes. I am feeling why should I learn a new language if it is same as the other. Can anyone please tell me why should I learn C?

I apologise for any misunderstanding. Any type of advice is appreciated.


r/C_Programming • • Feb 27 '24

“Anybody can be a programmer with AI” - Nvidia CEO Jensen Huang

0 Upvotes

Nvidia CEO Jensen Huang feels that AI will replace programmers and no one will require C or Java to do coding. I want to know what you guys think 🤔 of this??


r/C_Programming • • Aug 30 '24

Question Why do we use Null pointers?

0 Upvotes

If we want to "Nullify" something why dont we create a pointer in a controlled way that points to value 0?


r/C_Programming • • Dec 14 '25

Hey everyone again! What do you think of my new code? It's a school grades manager

1 Upvotes
// Edited 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>



// Data
typedef struct{
    float *grades_total;
    float average;
    float required_average;
    char name[250];
    char school_material[250];
    int n;
    bool student;
    int number_students;
} Data;



typedef enum{
    APROVED,
    REPROVED,
    UNKNOWN
} Student_Status;



void clear_input_buffer(){
    int c;
    while((c = getchar())!= '\n' && c != EOF);
}


Student_Status calculate_average(Data *data){
    float sum = 0;
    for (int i = 0; i < data->n; i++){
        sum += data->grades_total[i];
    }
    data->average = sum / data->n;


    if (data->average < data->required_average)
        return REPROVED;
    else
        return APROVED;
}


int main(){


    printf("Welcome to school grades manager! Press enter to start\n");
    while (1){
        Data *data = malloc(sizeof(Data));
        if(!data){
            printf("Internal error: Error to alloc a memory of data, please try close program and open again\n");
            return 1;
        }


        memset(data, 0, sizeof(Data));


        clear_input_buffer(); 


        printf("How many students you want? ");
        if(scanf("%d", &data->number_students) != 1 || data->number_students < 0){
            printf("Please write a valid number\n");
            clear_input_buffer(); 
            continue;
        }


        clear_input_buffer(); 


        Data *students = malloc(sizeof(Data) * data->number_students);


        for (int i = 0; i < data->number_students; i++) {
            printf("Write the name of student %d: ", i + 1);
            fgets(students[i].name, sizeof(students[i].name), stdin);
            students[i].name[strcspn(students[i].name, "\n")] = '\0';


            printf("Write the school material of student %d: ", i + 1);
            fgets(students[i].school_material, sizeof(students[i].school_material), stdin);
            students[i].school_material[strcspn(students[i].school_material, "\n")] = '\0';


            printf("How many grades you want for %s? ", students[i].name);
            scanf("%d", &students[i].n);
            clear_input_buffer();


            students[i].grades_total = malloc(sizeof(float) * students[i].n);
            for (int j = 0; j < students[i].n; j++) {
                printf("Enter grade %d: ", j + 1);
                scanf("%f", &students[i].grades_total[j]);
                clear_input_buffer();
            }


            printf("Required average for %s: ", students[i].name);
            scanf("%f", &students[i].required_average);
            clear_input_buffer();


            Student_Status status = calculate_average(&students[i]);
            if (status == REPROVED){
                printf("%s is reproved with average %.2f in %s\n", students[i].name, students[i].average, students[i].school_material);
            }
            else{
                printf("%s is aproved with average %.2f in %s\n", students[i].name, students[i].average, students[i].school_material);
            }
     
        }


        printf("How many grades you want? ");
        if(!scanf("%d", &data->n)){
            printf("Please write a valid number\n");
            clear_input_buffer(); 
            continue;
        }


        if (data->n <= 0){
            printf("Please write a valid number\n");
            clear_input_buffer(); 
            continue;
        }


        data->grades_total = malloc(sizeof(float) * data->n);
        if (!data->grades_total){
            printf("Internal error: Error to alloc a memory of data, please try close program and open again\n");
            return 1;
        }


        for (int i = 0; i < data->n; i++){
            while(1){
                printf("Enter grade %d: ", i + 1);
                if(!scanf("%f", &data->grades_total[i]) || data->grades_total[i] < 0){
                    printf("Please write a valid number >= 0\n");
                    clear_input_buffer();    
                } else {
                    clear_input_buffer();
                    break;
                }
            } 
        }


       
        for (int i = 0; i < data->number_students; i++){
            free(students[i].grades_total);
        }
       
        free(data->grades_total);
        free(data);


        char chosse[4];
        printf("You want to continue?\n");
        scanf("%3s", chosse);
        if(strcmp(chosse, "s") == 0){
            break;
        } else if(strcmp(chosse, "n")== 0){
            exit(1);
        } else {
            clear_input_buffer();
            printf("Please write 's' if you want to continue\n");
        }
    }


    return 0;
}

r/C_Programming • • Nov 08 '25

Question Why is my while loop only executing one line of code

1 Upvotes

Im an absolute coding beginner and i also only need it for one course in uni but we have an assignement on while loops and for some reason this while loop only executes printf("\n %d", seiteACT);

(everything up to int seitenL was written by my proffessor)

Code:

#include <stdio.h>


int main() 
{   
    int seitenL;
    int seiteACT;
    printf("\n Bitte geben sie die  gewünschte Größe der Raute ein:");
    scanf("%d", &seitenL);

    while(seiteACT != seitenL)
    {
        printf("\n %d", seiteACT);
        seiteACT + 1;
    }

    return 0;
}

r/C_Programming • • Sep 01 '24

Question Can anyone help me please? I'm learning for class and can't understand why the scanf() and printf() aren't reading correctly. It's been 2.5 hours and i cant figure out the problem.

0 Upvotes

include <stdio.h>

int main()

{

char productName[10];

int itemsSold;

float pricePerItem;

printf("What is the name of your product?: ");

scanf("%s", &productName);

printf("Product Name: %s", &productName);

printf("How many items were sold?: ");

scanf("%d", &itemsSold);

printf("Items Sold: %d", &itemsSold);

printf("How much is the product worth?: ");

scanf("%1f", &pricePerItem);

printf("Price/Product: %f", &pricePerItem);

float totalEarnings = (itemsSold * pricePerItem);

printf("Total Earnings: %f", &totalEarnings);

}


r/C_Programming • • Sep 05 '24

why using pointer?

4 Upvotes

im a new at C program. learned just before pointer & struct. i heard that pointer using for like point the adress of the parameter. but still dont know why we use it.
it seems it helps to make the program lighter and optimize the program? is it right? and is it oaky to ask question like this?


r/C_Programming • • Oct 01 '13

Resource C Style: my favorite C programming practices

Thumbnail
github.com
9 Upvotes

r/C_Programming • • Jan 12 '26

Is notepad++ and gcc better then using C online?

8 Upvotes

I am in a course learning C and they really dont want me to use C online,they want me to write in notepad++ uae gcc everytime i want to run the code and its annoying especialy because notepad++ is unsual to me and super annoying to use for now. So is there really a diffrence beetween using notepad++ and gcc than just using C online and if so which one is better?


r/C_Programming • • Jul 01 '26

Question How do the pre-increment (++x) and post-increment (x++) operators affect the values of variables in later statements of a program?

0 Upvotes

The pre- and post-increment operators change x and y to 6, but how is that possible when the following print function statements are separate and don’t contain ++? I know that ++x and y++ increment the variables by 1, but is it because the changes made by the increment operators persist after the first print function statements?

int main() {

  int x, y;
  x = y = 5;
      
  printf("%d\n", ++x +5);
  printf("%d\n", x); // 6

  printf("%d\n", y++ +5);
  printf("%d\n", y); // 6
}

r/C_Programming • • Sep 26 '23

C or C++

0 Upvotes

Hello everyone, should I learn C in parallel with C++, or is it better to stick to one language? What will you advice me?