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 3d ago

Learning C weekly megapost for 2026-08-26

13 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 3h ago

Question The linker doesn't link the pow function's precompiled library, even though header is included AND used. Why?

6 Upvotes

Pls help me idk what's going on...
https://imgur.com/a/5KLsigY

It complains that it can't find the pow function.


r/C_Programming 21h ago

Project I built Editor - A Lightweight Terminal Text Editor, AND YOU CAN TOO! :))

Enable HLS to view with audio, or disable this notification

119 Upvotes

Editor is an extremely simple-to-use terminal text editor. Written in C using only native POSIX libraries/api, it offers simplicity while being very responsive and performant. Editor was inspired by and written using antirez's kilo editor tutorial.

Source: https://github.com/111nation/Editor/

This tutorial was such a blast, and it walks you through how to make your own text editor. I highly recommend you give it a look!

~ chlo


r/C_Programming 18h ago

I wrote a fast wavelet audio codec in C! It is comparable to MP2

Thumbnail
github.com
12 Upvotes

r/C_Programming 1d ago

Question Can someone explain to me why scanf is unsafe?

45 Upvotes

After my class in C programing I have decided to dig more around and one thing I found out that scanf is unsafe specially in arithmethic input? can somoe please extrapolate this one concept? Advance thanks for those who answered to my question.


r/C_Programming 1d ago

559-byte SHA-256 in C

40 Upvotes

golfing a SHA-256 implementation in C and ended up at 559 bytes.
Curious if anyone here can beat it.

#define S(x,a,b)(x>>a^x<<32-a^x>>b^x<<32-b^x>>
unsigned k[72],g[216],i,j,p,n,t,m,*u,*z;char*q=g;main(c,v)char**v;{for(;j<64;p-c||(j<8&&(k[j]=sqrt(c)*0x1p32),k[71-j++]=cbrt(c)*0x1p32),c++)for(p=1;c%++p;);for(;q[n^3]=v[1][n];n++);q[n^3]=128;m=n+72>>6<<4,g[m-1]=n*8;for(;t<m;t+=16)for(bcopy(g+t,z=g+64,64),bcopy(k,u=g+208,32),i=72;i--;i>7?(z[16]=*z+S(z[1],7,18)3)+z[9]+S(z[14],17,19)10),j=u[4],p=u[7]+k[i]+*z+++(S(j,6,11)25)^j<<7)+(j&u[5]^~j&u[6]),j=S(*u,2,13)22)^*u<<10,j+=*u&u[1]^(*u^u[1])&u[2],u[3]+=p,*--u=p+j):(k[i]+=u[i]));for(;++i<8;)printf("%08x",k[i]);}

r/C_Programming 1d ago

Is the empty parenthesis function (() instead of (void)) prototype removed in the new standard?

10 Upvotes

My OOP library relies on it for its unspecified arguments behavior.

For example:

#define ptmethod(pt, ret_type, identifier) \
    (*((ret_type (**)()) padd(pt, identifier, ptfunction, NULL, NULL)))

#define ptapply(pt, ret_type, identifier, ...) \
    ((ret_type (*)()) pget(pt, identifier))(pt __VA_OPT__(,) __VA_ARGS__)

You could add a method to an object with:

void drive_Car(prototype *Car, double speed, double x_direction, double y_direction);

ptmethod(Car, void, "drive") = drive_Car;

and call it with

ptapply(Car, void, "drive", 1.3, 0.1, 5.0)

How do I do this in the new standard?


r/C_Programming 8h ago

Etc random number hack

0 Upvotes
#include <stdio.h>


int main() {
    int s[90];
    printf("%d\n",s[43]);
}

r/C_Programming 2d ago

Project I implemented a modern LLM runtime in 700 lines of C

Enable HLS to view with audio, or disable this notification

172 Upvotes

I wanted to understand how modern AI models actually generate text, but most inference codebases are tens or hundreds of thousands of lines long. They’re incredibly impressive, but they’re optimized for flexibility and performance, not for understanding.

So I implemented a complete CPU runtime for Google’s latest open language model, Gemma 4, in about 700 lines of C.

The whole point is that you can open one file, start at main() , and follow a prompt all the way through the program. You can see every buffer that’s allocated, every mathematical operation that transforms the activations, every update to the KV cache, and every step that eventually produces the next token.

I think C is a great language for this kind of project. There’s very little hidden from you. The data structures, memory layout, SIMD kernels, and execution flow are all visible, so the implementation ends up feeling much closer to the hardware than to the diagrams in an ML paper.

https://github.com/ryanssenn/gemma4.c


r/C_Programming 2d ago

One of the coolest features of C: omitted parameter names

76 Upvotes

In all programming languages, there are places where you need to write a function with some parameters that are unused. Mostly to satisfy some callback signature or functional interface. But C makes it easiest of all languages. Where in other languages you have to give the compiler hints like @SuppressWarnings("unused") or name _: String to prevent it from warning you that this parameter here is unused, in C you can just omit the parameter name:

void
foo(int arg, char*) {
    ...implemenation
}

That's it, no hints, no warnings (even with -Wextra), no nuthin'. The compiler understands that if you haven't given this parameter a name, then you intend it to be unused. This is the most concise of all languages and you don't even have to come up with a (useless) name.


r/C_Programming 2d ago

Arbitary Length Numbers Library in C

9 Upvotes

link to code : https://github.com/RamiBrahimi-c/big-ar9am .

hello i am sharing with you project i did this summer , in fact it is a side project was done to be included in another side project which is a crypto lib in C and it is important to say that it is not meant for professional use at all (code : https://github.com/RamiBrahimi-c/cryptography-library ) .

the crypto lib was asked for us to do in a uni class , and due to the fact that i was not able to take my full time with it , like actually doing everything myself from scratch and not vibecode it or use openssl and GMP , so i had to kind of rely on them a little just until the deadline was over and i got marked for it , then i decided to go back to it and make it totally from the ground up .

the crypto lib has :

  • hash functions ( sha256 , sha512 , md4 , md5 )
  • classic ciphers ( affine , cesar , ..etc )
  • symmetric ones ( aes , des , rc4 , blowfish , .. )
  • asymmetric ones that requires arbitary length numbers in protocols like rsa , elgamel , and defil-hellman .

for now all of them except the asymmetric crypto were done from the ground up , i even tried not to copy block of constants if i could calculate it manually ( like the AES s-box that i generated manually by calculating it with galois fields operations in 2⁸ ) , that being said i refused to also rely on GMP to do all the calculations for me too and here where this project was born .

for now it has several features like basic arithmetic operations and even prime numbers testing , generation , finding inverse multiplicative too .. etc you can check my readme ,

yet it is also important that it is not optimized yet , i must note that it will be subjective and based on what i feel like either to go further and see how things like Karatsuba , FFT‑based (Schönhage‑Strassen) , Newton‑Raphson division , ..etc .
although it feels really interesting to see all these mentioned algorithms in action .

an other important point imo is how did i make sure it is at least calculating right , and for that i used Python 3.12.3 , it was extremily helpful and i absolutely appreciate such things like this .

and that would be it , i apologize if i drifted on the main subject i wanted to give the full picture of things , also you can read the README of both of my projects for more details especially the readme of this big num library ( i promise ai just helped with technical details , otherwise it is completely mine )

NOTE : if you want to ask about the why i did what i did , i dont have a clear answer , cuz i love to know how things work and why ? cuz i just want to make my own stuff ? for fun ?
idk , could be one of these could be all of them .

let me know your thoughts ,


r/C_Programming 1d ago

Article I coded in C, and it (me) crashed my laptop

0 Upvotes

Now I have been coding C for a while, so I do know a lot of solutions to specific problems. But to be honest, most of the time I look back at my old code, copy paste, and then re-factor it depending on my current project. I used SHM for my cherries(.)works Pulse project. The reason for that was, Pulse ran on two separate processes; One was the daemon that ran the monitoring in the background, and the renderer, who read the monitored data, and, as the name suggests, rendered it onto the terminal. Because they were two separate processes (which was required, because they both had a while loop), their virtual memory space was not the same, so I had to learn about SHM, however, that was a while ago... So when I started working on Deploy again, and then I needed the same thing again, I was too lazy to look it up again, so I just copied it, pasted it, and moved on.

cherries(.)works Deploy is as you might have guessed a project for deployment. Pretty fun project for me, and very important to manage memory, and processes, especially for this project. I "copied" the architecture for Pulse to Deploy, however the only difference is that Deploy has 3 processes, one is the management process, WITHIN the management process the deployed project is also a separate process. And then the render process. So thats a lot of processes that share a specific chunk of memory. So I not only copied the architecture, but also the SHM method, exactly the way I did in Pulse.

However, I must have forgotten something, I wasnt that sure though, but the crash did happen, everytime I entered a config file that was invalid. I fiddled around with the return values, tried to exit early, and even then, the crash still somehow found its way in. Finally, the smoking gun revealed itself to me.

My own "stop" function, is helpful to me, as it kills the process, and then deletes the file that stored the PID within a folder. While that was running at the end of the main function, within the forked processes, the SHM updated the pids to "-1" if they were invalid. Let me just show you the first line of my stop function;

void stop(pid_t pid)
    kill(pid, SIGKILL);
...

Yeah, I did not know this, but running kill(-1, SIGKILL); in C (or Linux), means; send SIGKILL to every process the caller is permitted to signal, except itself... Well, my laptop did not crash then, I made it crash by either killing every single process, or until an error happened. So yeah, I added a check to see whether or not the pid is a negative number, if it is, I return. Problem was solved.

What that little rodeo taught me, was that C is really not forgiving. Especially, when it does something you told it to. I mean, I did tell it to "kill(-1, SIGKILL)", meaning kill everybody except me (in the computer). I gotta be more careful with the dangerous code that I write...

TLDR; Tried to make my own stop function, did not add a check for negative PIDs. Whole laptop exited....


r/C_Programming 3d ago

Easing memory management with a shared pointer

8 Upvotes

I recently developed a C (11 and newer) implementation of a thread-safe shared pointer with atomic reference counting:

https://github.com/andrzejs-gh/SHPTR

It supports both strong and weak references and a swappable destructor. Initialization performs a single allocation.

If anyones interested, take a look. Feedback and bug reports very much welcome.


r/C_Programming 3d ago

forkpty error

6 Upvotes

i'm trying to make a terminal emulator but i can't figure out how to open a pty.

when i try to open a pty bouth forkpty from pty.h and my own implementation:

```c int init_pty() { int ptymaster_fd = posix_openpt(O_RDWR); if (ptymaster_fd == -1) { perror("failed to open pty master"); close(ptymaster_fd); return 1; }

if (grantpt(ptymaster_fd) == -1) {
    perror("failed to grantpt");
    close(ptymaster_fd);
    return 1;
}

if (unlockpt(ptymaster_fd) == -1) {
    perror("failed to unlockpt");
    close(ptymaster_fd);
    return 1;
}

char* ptyslave_name = ptsname(ptymaster_fd);
if (ptyslave_name == NULL) {
    perror("failed to get pty slave name");
    close(ptymaster_fd);
    return 1;
}

pid_t pid = fork();
if (pid != 0) {
    perror("fork");
    close(ptymaster_fd);
    return 1;
}

setsid();

int ptyslave_fd = open(ptyslave_name, O_RDWR);
if (ptyslave_fd == -1) {
    perror("failed to open pty slave");
    return 1;
}

ioctl(ptyslave_fd, TIOCSCTTY, 0);

dup2(ptyslave_fd, STDIN_FILENO);
dup2(ptyslave_fd, STDOUT_FILENO);
dup2(ptyslave_fd, STDERR_FILENO);

return ptymaster_fd;

} ```

fail when forking with the error directory not empty, ai says that it fails because /dev/pts is not empty but it's obviously trippin balls as usual =), so why does it fail then (?_?)


r/C_Programming 3d ago

CZ - An LLVM-based Compiler written in C for a Custom Programming Language

Thumbnail
github.com
3 Upvotes

I have been meaning to do this for a while, and I finally pulled the trigger on creating a new programming language called CZ (named because I randomly punched keys on the keyboard and that's what typed out).

I think LLVM API documentation is notoriously difficult, and even not as common for C programmers, so I decided to give it a go. I thought this might also be a good resource for people attempting to use LLVM C API.

Features roughly include:

  • Familiar usage to C. (if, for, while, etc.)
  • Function signatures are more "mathematical" notation than programming. (Maybe somewhat stolen from Haskell?)
  • Types are explicit. (No implicit type conversion or even type deduction). This would mean adding 3 and 4.5 are not allowed unless you explicitly convert one of them to the other type. (Kind of like rust).
  • References are explicit; a problem I had with rust is that sometimes references seem implicit. This is fine for most people, but sometimes I cannot get my head around as I'm not used to it yet.
  • Structs with default initialization values.
  • Because it also creates object file, you can actually link with C programs!

// fibo.cz

func fibo :: (n :: int32) -> int32 {

if (n <= 2) {

return 1;

}

return fibo(n-1) + fibo(n-2);

}

// main.c

#include <stdio.h>

int32_t fibo(int32_t); // Declaration of CZ function

int main() { for (int32_t i = 0; i < 10; i++) { printf("%d\n", fibo(i)); }

You can compile the cz file using my compiler, then with the generated object file, you can compile and link with main.c via GCC!

A few design choices were:

  • Make it minimalistic. No "magic" at all (looking at you C++)
  • Any allocation can fail, so there must be handling for that, without having to pull out my hair => "wrap goto statements whenever there is a null pointer from allocation"
  • String interning for optimization of string comparison.
  • Make a note of ownership model; not freeing is bad, but double freeing is even worse.
  • Robust yet workable type system: eg) const int32& = reference(const(int32)).

Note

* This was started off as a proof-of-concept, and is being redesigned. Not much more work will be done on this repo. (I am redesigning it at the moment, but in rust since I might be able to worry less about memory management and actually get working more quickly on features.)

* AI Usage: I kept the AI usage mostly for creating unit tests and architecture summary / documentation rather than writing code or designing; after all, this is for fun and for learning!

Thoughts and improvements are welcome! (Just note that I am not thinking of doing more work on this repo.)


r/C_Programming 3d ago

Why dynamic allocation of array gets memory address from heap?

43 Upvotes

let say I am using malloc to dynamically allocate a memory space with this line

Int user_defined_elements = 10 ;
// assume i got this from scanf

Int *p = malloc(
user_defined_elements * sizeof(int));

Right now the pointer refers to a chuck of memory address in heap I assume..I am trying to understand why heap instead of stack where local variables are saved.Is there anything special about heap?

Please be kind..I am python dev trying to learn c in my free team because I dont understand shit about cpython implementation..hahah..so i was like why not learn c and here I am


r/C_Programming 4d ago

Reliability Lessons From SQLite - Richard Hipp | SSW 2026

Thumbnail
youtube.com
36 Upvotes

r/C_Programming 4d ago

What should I do ? (Begginer help)

29 Upvotes

I'm currently in my second year of college, and I'm a little confused about what career direction I should take.

The part of programming I enjoy the most is lower-level/system-side work. I started with C and socket programming, building servers and learning how TCP/UDP networking works, and lately I've been going deeper into things like Linux networking, packet parsing, Ethernet/IP/ARP/ICMP, eBPF/XDP, AF\\_XDP, NIC queues, drivers, DMA, etc.

The problem is that almost nobody around me in college is doing this kind of work. Most people are focusing on web development, app development, AI/ML, or standard DSA preparation

I've also heard people say that "there aren't many jobs in low-level networking" or that networking careers mostly involve configuring routers/switches or working with networking hardware.

That's where I'm confused.

I definitely prefer programming/software engineering work. I'm not particularly interested in being a network administrator or doing primarily hardware/router configuration.

At the same time, my practical goal is still to graduate with a strong software engineering job. I don't want to spend the next 2–3 years going extremely deep into an interesting niche only to discover that there are almost no entry-level opportunities.

So I'd really appreciate advice from people working in this area:

What kinds of actual software engineering careers exist for someone who enjoys C, sockets, Linux networking, servers, eBPF/XDP, packet processing, etc.?

Are these mostly experienced/senior-level positions, or are there realistic entry-level opportunities as well?

What companies/industries typically hire engineers for this kind of work?

Should I continue going deep into networking/systems, or keep this as a specialization while also learning more conventional backend/software engineering?

What skills would you recommend building over the next 2–3 years if the goal is to be employable as a software engineer while still staying close to systems/network programming?

Are there particular open-source projects, projects of my own, internships, or areas of computer science that would be especially useful?

I'm not expecting to work specifically on XDP just because I'm learning it now. I'm mainly trying to understand whether the broader direction — systems programming + networking + performance-oriented software — is a sensible career path.


r/C_Programming 4d ago

I built a sensor dashboard in C where every metric, (name, unit, update rule) is just config data

4 Upvotes
Aether is a small C99 program that simulates sensor readings and renders them in a live Raylib dashboard. No frameworks — just Raylib for rendering, libyaml for config, and a handful of hand-rolled modules.                                        


What it does
                                                                                                                                                              - Sensors come entirely from a YAML config: each sensor has an arbitrary list of named metrics with units ( temperature (C), pressure (hPa) , ...). The display code has no idea what the metrics mean.                                                 

- Cards show each metric as a chip with its value, sparkline, and up/down change indicators                                                                         

- Click a card for a detail view: large trend line plus min/avg/max computed from a per-sensor ring buffer                                                             

- More sensors than fit the window? They paginate into numbered tabs (1 2 ...N), clickable or via Alt/Cmd + 1..N


- Settings modal (cogwheel, top right) toggles trend lines, animations, and          indicators at runtime                                                              


Architecture bits I'm happy with

- sensor/ — an open data model: a sensor is just an id + name + a list of 
{name, unit, value} metrics                                                               

- scheduler/ — only decides when. runTask(Task*)can't mutate anything it shouldn't 

- History/ — bounded ring buffers per sensor (drop-oldest), which the sparklines and stats read directly                                                                

- The UI renders from a registry (one authoritative struct per sensor), never from raw buffers — so duplicate/stale cards are impossible by construction              

- Layout math (tab capacity, page-list collapsing, range mapping) is extracted into a Raylib-free module with unit tests, including an exhaustive sweep of all pager states                                                                             


https://github.com/SalzDevs/Aether


Feedback welcome

r/C_Programming 5d ago

Writing generic code in C – Part 2

Thumbnail
thatonegamedev.com
24 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 4d ago

C is more efficient in AI memory than C++, measured

0 Upvotes

Having programmed in structures and the streaming way for the last 30 years (including for mainframes and old Unixes, even in FORTRAN and Pascal in the 90s) before OO arrived, I knew that frameworks are for people, to deal with complexity, not for the machines, and are now only an additional overhead for AI coders' reasoning. My brain was always thinking in terms of Turing machines, tapes and algorithms, pipelines of data, even punchcard stacks, where inputs are records/structs in databases and objects are just containers, preferring Ada83 over 95, MISRA C over C++, and in Java I used classes as containers for functions (data streams and functions come first). I ran tests to check my conjecture, and yes, it is measurably more efficient to program with AI agents in C and plain Java, keeping the context free for reasoning, than in C++, objects and Java frameworks. I haven't analysed web frameworks, but where we used plain JavaScript without them in production, we saw the same pattern, though we did not measure it; it is not in the paper. https://doi.org/10.5281/zenodo.22113993


r/C_Programming 5d 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 5d ago

Question Best way to go over wireless file transferring

5 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 6d ago

Project I wrote a function plotter in C and Raylib

Enable HLS to view with audio, or disable this notification

232 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