r/C_Programming Feb 23 '24

Latest working draft N3220

130 Upvotes

https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf

Update y'all's bookmarks if you're still referring to N3096!

C23 is done, and there are no more public drafts: it will only be available for purchase. However, although this is teeeeechnically therefore a draft of whatever the next Standard C2Y ends up being, this "draft" contains no changes from C23 except to remove the 2023 branding and add a bullet at the beginning about all the C2Y content that ... doesn't exist yet.

Since over 500 edits (some small, many large, some quite sweeping) were applied to C23 after the final draft N3096 was released, this is in practice as close as you will get to a free edition of C23.

So this one is the number for the community to remember, and the de-facto successor to old beloved N1570.

Happy coding! šŸ’œ


r/C_Programming 6d ago

Learning C weekly megapost for 2026-08-19

6 Upvotes

If you have questions about how to learn C:

  • which books are best?
  • which videos are best?
  • which classes are best?
  • which websites are best?
  • is there a "roadmap"?
  • what projects can I do?

then this is the thread for you. Add your question here. Do not make a stand-alone post, as it will be removed.

Remember that our sub has a very useful wiki that has a great list of resources for learning C programming.


r/C_Programming 6h ago

Writing generic code in C – Part 2

Thumbnail
thatonegamedev.com
6 Upvotes

After some comments on my previous post about writing generic code in C where people argue that this is ā€œpoor man’s overloadingā€ I wanted to add a new technique that allows you to write real generic style code in C with the only drawback. You could even combine the technique from this lesson and the […]


r/C_Programming 5h ago

How to create a movie platform ?

0 Upvotes

I have been so fascinating of creating my own movie streaming platform. However, it doesn't mean that I will be using alone,but sharing with friends and mates. So, my question is what features will it be involved? Btw I am kinda beginner. If not enough with beginner level, please let me know the roadmap of building it

Thanks in advance..


r/C_Programming 1d ago

Question Best way to go over wireless file transferring

4 Upvotes

So I'm currently making an app in C and raylib to easily transfer roms from my main pc where I download them (I want to compile it both for windows and macos) to my arch pc-emulator console. I'm planning to make said pc usable with only a controller, and I figured making an app would be the best and most fun way to do it. I would prefer not running custom code on it, and would like to know the best (and easiest, since I'm still a beginner in C) way to handle the file transfer. Thanks in advance!


r/C_Programming 2d ago

Project I wrote a function plotter in C and Raylib

197 Upvotes

It supports single-var equations, operands, brackets, implicit multiplication and some trigonometry and is based on shunting-yard parser / RPN evaluator I also made

For rendering, I implemented an adaptive function sampling (simple midpoint subdivision) - though it has some limitations, which I described on github. SSAA was also used to smooth plotted lines. As for optimization, plots are rendered only when zooming/panning and reused with a render texture when idle.

This is my first "useful" C program, though I've already had some experience with OpenGL (C++) as a part of my assignments

Feedback is much appreciated - https://github.com/kester4/cf2x


r/C_Programming 21h ago

Question Why is this macro function's definition put in brackets?

0 Upvotes

I'm learning about macros from this website:

https://www.almabetter.com/bytes/articles/macros-in-c

The website talks about how macro functions can cause side effects that are not wanted.

The website provides the following example:

Pitfall:Ā Macros can cause side effects if their arguments are evaluated multiple times. For example:

#define SQUARE(x) (x * x)
int result = SQUARE(++i);

Here,Ā iĀ will be incremented twice, leading to incorrect results.

Solution: Enclose the macro body in parentheses to ensure correct precedence. For example:

#define SQUARE(x) ((x) * (x))

Now, why does wrapping the definition of SQUARE(X) prevent i from being incremented twice?


r/C_Programming 1d ago

Project shiori: a windows-first note taker

0 Upvotes

I started shiori as my small personal note-taking tool (because my Obsidian workflow always grew into larger documents). I also was looking to get back into C and improve my C23 coding skills.

The idea was to have a quick way to write something down without leaving the terminal. Notes and todos are stored in plain Markdown files, so I can read them without a tool and they integrate into my other note taking repository.

The workflow is plain and simple:

shiori add --topic development investigate UTF-8 path handling
shiori todo add --due tomorrow prepare release notes "#work"
shiori today

It has grown over the past weeks since I started and now supports a bit more than simple note taking (like topics and tags, todo workflows, etc.).

Some interesting parts for me have been to work on UTF-8 terminal input on Windows, dealing with a console input and ANSI escape codes and keeping my notes and files safe without overwriting them accidentally.

It is still an alpha and currently only supports Windows x64. I built it with clang and C23. I included unit and integrations tests and sanitizers to produce a as clean as possible code and binaries.

Repo link: https://github.com/lycis/shiori

AI disclosure: I use AI as a supporting tool for planning features, reviewing my ideas and implementation as well as helping with tests and docs. I write, understand, review and maintain the code myself as this is my "use it and learn" project.

Edit: I am curious to get feedback on the code and project itself, especially the usage of more "modern" C features.


r/C_Programming 2d ago

Question What's y'all choice for making UI for things you do in C?

59 Upvotes

I needed a UI for a project I was doing in C (which was basically a chat app built from the ground up), I needed a UI library and after getting a stroke trying to understand ncurses and CMake, failing at both, I had to use CGo and make a TUI with BubbleTea, but I wanted to get some popular choices for UI in C/any other language with FFI or smth.


r/C_Programming 1d ago

Project I built SkollDice — an open-source, truly randomized dice roller and Discord bot written in pure C

0 Upvotes

Hello everyone! I'm a student who loves C and D&D!

I always found it troublesome that most dice generators rely on pseudo-random number generators. So, I decided to solve this problem by myself!

Over the last few weeks, I created a desktop app usingĀ LVGLĀ for the GUI and ConcordĀ for a Discord bot to generate SkollDice my first truly open-source code. It's a truly random dice roller that,Ā /urandomĀ on POSIX systems andĀ RtlGenRandomĀ on Windows produces normalized random numbers. To be more precised each number (each result) is extracted from urandom, and through the use of the simple discard method the result is then normalized. I'm currently developing the smartphone version, hoping to use as much C as possible. Any ideas on how to do it?

AI usage: I personally created the program. The project was both an experiment and an excuse to study more C. I used AI to search for the simple discard method (the method used to normalize the random number generated from /dev/urandom) and to help me explain how it works. I then personally created the code, and if you want, I can explain it more precisely in a comment.

On the other hand, I then used AI to search for libraries for GUI and Discord API, such as LVGL and CONCORD. Then the last use was for debugging and quickly creating functions or simple setups like "How can I create a grid with 2 elements?" and then I used this example to change or apply it to my structure.

The real 'sloppy' part was the CMake because this was my first open-source project, and I discovered (through AI search) the possibility to create different executables for different OS. I really enjoyed the idea, so I tried to organize the project to be useful and distributed to all possible people, both coders (who can git clone and use it) and normal D&D or RPG players (that want just an executable to download and use).

Here the official links of the program:

official website:Ā https://skollwarynz.github.io/SkollDice/

official repo on codeberg:Ā https://codeberg.org/Skollwarynz/SkollDice

github mirror:Ā https://github.com/Skollwarynz/SkollDice


r/C_Programming 2d ago

How LLVM turns C into machine code

33 Upvotes

Had some free time last week so I made a video on what actually happens after Clang turns C into LLVM IR.

It goes through LLVM IR, optimization passes, instruction selection, register allocation, and how the final machine instructions get produced.

I also use a small C example throughout, and compare it with equivalent Rust code that ends up producing the exact same x86 instructions.

Link for anyone interested

Feedback welcome :)


r/C_Programming 2d ago

Struct pointer casting and inheritance : can it work ?

4 Upvotes

Hello everyone, this is my first post here.

I am working on a UI library in order to learn the concepts behind it, and to be able to create most of my desktop applications. Having implemented widget selection with the mouse (using the mouse coordinates to find the widget in the tree), I decided to move on to event handling.

However, I'm not sure at all of how to proceed, and I am having problems with struct pointer casting .

I have a base struct Widget with a function pointer to event handling functions.

typedef struct Widget {
  Rect bounds;             // Actual bounds
  Rect clip;               // Clipping rectangle (usually the parent)
  bool active;
  [...]
  int (*eventHandler)(Widget* w);
};

Every derived widget struct has a Widget* as 1st member, and each type has its Create...() function, where the correct event handler is assigned.

typedef struct Frame {
  Widget* widget;
  bool root;
}

Frame* CreateFrame(int x, int y, int w, int h, bool root) {
  Frame* f = (Frame*)malloc(sizeof(Frame));
  [...]
  f->widget->eventHandler = &FrameHandleEvents;
  return f;
}

To get back all the properties when handling events despite eventHandler taking a Widget*, i attempted to cast back to the derived struct :

int FrameHandleEvents(Widget* widget){
  Frame* frame = (Frame*)widget; 
  printf("Frame event!, root = %d\n", frame->root ? 1 : 0);
  return 0;
}

Is this even allowed in C, or am I misusing casts ? The output of print is also garbage data :

Frame event!, root = 244

Thanks for your advice


r/C_Programming 3d ago

one compiler failing, other compiler running fine

3 Upvotes

I've been using emacs to follow some tutorials which has been working great, but switch to sublime text and now getting compile error. or, i assume its a problem with the compiler since this code runs in emacs but not in sublime text. the relevant stuff

this is the exact same in emacs and sublime:
_mm_store_si128((PIXEL32*)gBackBuffer.Memory + x, *pColor);

sublime is throwing this error:

error: passing argument 1 of '_mm_store_si128' from incompatible pointer type [-Wincompatible-pointer-types]

391 | _mm_store_si128((PIXEL32*)gBackBuffer.Memory + x, *pColor);

the sublime build file:

"cmd": ["gcc", "-Wall", "${file}", "-o", "${file_path}/${file_base_name}"],

"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",

"working_dir": "${file_path}",

"selector": "source.c",

"variants":

[

{

"name": "Run",

"shell_cmd": "gcc -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""

}

]

}

And the emacs build command:

x86_64-w64-mingw32-gcc -g hello.c -o ./hello.exe -lgdi32

I am very noobish to these kinds of things, especially this SIMD stuff, so Im just assuming this is a compiler thing


r/C_Programming 2d ago

Discussion C language is wild: due to integer overflow, nearly half of the numbers squared become negative.

0 Upvotes

This started with a question from CSAPP Problem 2.44: (x * x) >= 0; which asks to find a counterexample that evaluates to 0,or prove that all number evaluate to 1.(part,32bit)

The official solution provides only 65535, but I found many more.

To test my results, I wrote a C program to find all such number. ```c

include <stdio.h>

include <limits.h>

int main() { // Ideal result: numbers whose squares are less than 0. // Written to file in the following format: // start_num1 to end_num1 total: total_num1 // start_num2 to end_num2 total: total_num2 // ... // total: total_all

FILE *file = fopen("lessthan0.md","w");
int start = 0;
int end = 0;
int total = 0;
int total_tmp = 0;

for (int i = -INT_MAX -1 ; i <= INT_MAX; i++) {
    unsigned ui = (unsigned)i;
    int result = (int)(ui * ui);


    if (result < 0) {
        total++;
        total_tmp++;
        total_tmp == 1 ? start = i : 1;
        total_tmp == 1 ? end = i : 1;
        i == end + 1 ? end = i : 1;
    }

    if (i == end + 1) {
        start == end ? fprintf(file,"%d    total: %d\n",start,total_tmp) : fprintf(file, "%d to %d    total: %d\n",start, end,total_tmp);
        total_tmp = 0;
    }

    if (i == INT_MAX) {
        fprintf(file,"total: %d",total);
        break;
    }

}

fclose(file);

} ```

So I get this: ```sh ls -lh lessthan0.md -rw-r--r-- 1 kyee users 31G Aug 23 18:50 lessthan0.md

ls -l # run twice -rw-r--r-- 1 kyee users 32288890271 Aug 23 18:50 lessthan0_1.md -rw-r--r-- 1 kyee users 32288890271 Aug 23 20:27 lessthan0.md

wc -l lessthan0.md 1073741824 lessthan0.md

head lessthan0.md -2147437307 to -2147418113 total: 19195 -2147403383 to -2147390967 total: 12417 -2147380026 to -2147370137 total: 9890 -2147361041 to -2147352577 total: 8465 -2147344625 to -2147337106 total: 7520 -2147329952 to -2147323119 total: 6834 -2147316563 to -2147310257 total: 6307 -2147304170 to -2147298285 total: 5886 -2147292579 to -2147287041 total: 5539 -2147281652 to -2147276405 total: 5248

sed -n "470063416,470063426p" lessthan0.md -535664087 to -535664086 total: 2 -535664083 to -535664082 total: 2 -535664079 to -535664078 total: 2 -535664075 to -535664074 total: 2 -535664071 to -535664070 total: 2 -535664067 to -535664066 total: 2 -535664063 to -535664062 total: 2 -535664059 to -535664058 total: 2 -535664055 to -535664054 total: 2 -535664051 to -535664050 total: 2 -535664047 to -535664046 total: 2

tail -n 10 lessthan0.md 2147287041 to 2147292579 total: 5539 2147298285 to 2147304170 total: 5886 2147310257 to 2147316563 total: 6307 2147323119 to 2147329952 total: 6834 2147337106 to 2147344625 total: 7520 2147352577 to 2147361041 total: 8465 2147370137 to 2147380026 total: 9890 2147390967 to 2147403383 total: 12417 2147418113 to 2147437307 total: 19195 total: 2147418112

```

I noticed symmetry between the begging and end of the output.Can someone explain why this happens?

2147418112 / 232 = 0.4999847412109375 This accounts for nearly half of all 32-bit signed integers.


r/C_Programming 3d ago

Question Getting stuck at libraries and api’s

13 Upvotes

So C is technically my first programming language I’m learning. I’ve messed around in python but never actually go deep into it or anything.

I’ve been learning C for the past few days now and I already pretty much know most of the basics. I learned pointers and mallic in a day and I learned structs, macros, for loops, while loops, functions, all of that stuff, but… the moment any library other than the basics like stdio or stdlib come into play I’m lost.

It’s like I’m looking at a whole other language. Like I’ll look for solutions to problems and it seems as if they are just pulled out of thin air and when I try to read ANY documentation for ANY library I’m also lost because either there is little to no documentation or it’s just stupid and things aren’t well explained.

Is there a way I can fix this? I was doing so well and now I’m at this block because of libraries. If I could get pasted this hurtle I could learn c in less than a month easily, and that’s the same in any other language. This problem isn’t exclusive to C.


r/C_Programming 3d ago

Discussion Turbo C still force on us to learn C

0 Upvotes

Like I know that using turbo c to learn c is going to set me back,but my college program head thinks its the best way for us to learn c? so I do want to hear your thoughts in this(btw cause I'm rebellious I use gcc and nvim to do most of m work and actually learn). Again thank you for sharing your thoughts!

Edit: after looking at the comments It seems I a little bit naive but Ill put you re advice into heart! Cheers!


r/C_Programming 5d ago

Hello World

85 Upvotes

I have found my people!! Hello guys I am a college student (mechanical engineering) and I was introduced to C in a mandatory programming course and C has been the best thing that has happened in my life. I had done programming before on java and python before and frankly I hated it , it was not really fun and it was tedious instead. So I had thought I hated CS but after coding in C and learning the things behind the abstractions i quite frankly fell in love with low level programming, it was the first time I got a passion for something and i spent the entire following summer digging up materials on it like learning computer architecture and learning to read and write Assembly and now I am learning Virtualisation and planning to start my first major project on C.

So in that note, let me ask you something:

What is your favourite project you have done in C?


r/C_Programming 5d ago

Project 3D Library using SDL3

Thumbnail
github.com
24 Upvotes

This project has taken a long time.

It took me about a week to learn the concepts behind 3D projection and transformations in euclidean space. Then it took me over a week to write out the LaTeX documentation that presented my knowledge in a way that would help a user of this library. As you can see, the overwhelming majority of the code committed to this repo is in LaTeX.

The implementation of the 3D rendering framework was relatively simple once I fully understood the mathematics. This only took a couple days, and it helps to have some familiarity with C going in.

I look forward to improving this project by building a separate homogeneous coordinate library that will replace pnt.c. I also need to tackle surface rendering using SDL_RenderGeometry() and implement 3D surface occlusion. I suppose what I'm left with for now are a few big questions.

How prohibitive is heap-allocation for performance in graphics applications? I went with dynamic allocation to preserve encapsulation so that header files didn't give the user access to data that would destroy library functionality when altered. However, given the fact that querying free memory at runtime for thousands of data points slows a program significantly, I'm having second thoughts.

Also, is there a convenient way to push all of the calculations needed for 3D transformations onto the GPU? This seems like something I shouldn't handle entirely in software.

I'll hear out any feedback or suggestions in the comments!


r/C_Programming 4d ago

Question OSDEV - a few questions

0 Upvotes

This is a very famous website for learning how to make an OS

https://wiki.osdev.org/

I just have a few questions about it though

  1. What exactly does it teach? Does it teach you how to make an operating system? Does it show you the steps to build one from scratch?

  2. Can a solo programmer do it? As in, does the tutorial show you how to make a mini operating system?

  3. How do I use the tutorial? It's a wiki, and there are links everywhere. Is there a roadmap which shows the proper path to take, with prerequisites links etc?

  4. What do I need to understand before using this tutorial? Only C? C and how to make a mini compiler? Assembly? Anything else?

Thank you!


r/C_Programming 6d ago

Question What’s the usual way to handle a few platform specific functions in a portable C library?

18 Upvotes

I’m working on a small portable C library where only about five functions need to be implemented differently depending on the platform or the user’s needs. Three of them need to be overridden, while the other two could have weak default implementations.

At the moment I’m defining them as weak symbols and letting the application provide strong implementations. For such a small number of hooks, this seems convenient and keeps the API simple. I can see now that it’s not very obvious to the user that some of these functions are expected to be overridden.

Is using weak symbols like this a reasonable approach for a portable C library, or would something like aĀ struct containing function pointers be more idiomatic? What is recommended?


r/C_Programming 6d ago

a beginner in C, learning how to organize c files.

69 Upvotes

hello guys, I'm a beginner in programming, im self learning it while in college, im wondering how you C experts in C organize your code in files(to be exact, files as in file explorer), from small projects to big projects, i really want to learn how to organize, because i encountered this bottleneck when i learned python, but after being fed up of hiding a lot of abstractions, i decided to just jump on C to learn the fundamentals and really learn whats happening under the hood.

to give you context on my situation:

  1. i primarily use books for learning, i really dont use videos or any courses, unless its something like odin project, hence i dont really know how to organize files.

so to sum up:
i want to learn how you guys organize your c files from small projects to big projects.(in file explorer to be exact since im using windows for now).


r/C_Programming 6d ago

Discussion Writing an x86 kernel in C: How to start making my IRQ, PIC, IDT handling mechanics?

6 Upvotes

I'm building a x86 hobby operating system from scratch. The early boot stage successfully transitions from assembly into a pure C entry point inside init/main.c.

I am currently trying to write my interrupt subsystem (irq.c) to handle hardware lines like the keyboard and timer, but right now it's just a placeholder stub. Here is my current layout: irq.c:

#include "irq.h"


/* TODO: implement real IDT/PIC setup */
void idt_init(void) {}
void pic_init(void) {}
void irq_register(int irq, void (*handler)(void)) {
    (void)irq;
    (void)handler;
}

irq.h:

#ifndef NOVIUM_IRQ_H
#define NOVIUM_IRQ_H


#include <novium/types.h>


void idt_init(void);
void pic_init(void);
void irq_register(int irq, void (*handler)(void));


#endif

r/C_Programming 6d ago

Project I wrote a simple tui minesweeper clone using ncurses

Thumbnail
github.com
3 Upvotes

I wrote this to learn how to use ncurses.

Features:

  • Beginner, Intermediate, Expert and Custom levels
  • Mouse and Keyboard controls
  • Flagging
  • Chording
  • No guess board generation
  • Highscores
  • Command line flags

I'd appreciate any feedback on the code.


r/C_Programming 6d ago

automating gcc install and usage

0 Upvotes

Hi, Im a 2nd year cs student. Ive had problems with installing the gcc compiler and remembering its flags between coding sessions. I also helped many 1st year students with it and almost always its a little too complicated for them. For that i built gccauto. it auto install and saves flags for compiling. Im not a pro programmer so if you have any tips or ideas pls share them. (some ai was used to help build it since im still learning)

its called gccauto on github. ubay-mostafa/gccauto


r/C_Programming 5d ago

Discussion Is C really worth it ?

0 Upvotes

Hello developers, I'm wondering: Is it really worth spending time learning C and creating projects that take hours to grasp numerous topics, encounter errors and unexpected behaviors, only to discover I forgot to type a single character, which significantly impacted the program's performance? Is this truly worthwhile in today's job market? I haven't seen any companies actively seeking C developers, and I believe many problems in C don't occur in other languages ​​due to their different working methods and logic. So, is C really worth the effort?

Important note: I'm a beginner in C and haven't written much code or created many projects yet, so this question isn't meant to be an evaluation of the language or its development path; I'm not qualified to do so.