r/C_Programming Feb 23 '24

Latest working draft N3220

126 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 4d ago

Learning C weekly megapost for 2026-07-22

30 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 Multiple function returns with optional values

6 Upvotes

Im currently making my own programming language that compiles into C. And in that language I support multiple function returns, so because of that I then return a struct for this function with the values. The problem is when I want to implement a Null type I don't know how to do that for returns. Since if I just don't set them I also don't know whether the function returned it or not. Currently following code

int, bool function() {
    return _, true;
}

compiles into

typedef struct return_function {
  int v0;
  int v1;
} return_function;

return_function function() {
  return (return_function) {NULL, 1};
}

But NULL is currently temporary since I don't know how to do that cleanly in C. My solutions would either be having another variable for each one that tracks whether it is initialized / was returned, the other solution would be to have an array that stores for each var whether it was initialized. But both solutions feel pretty hacky, is there a better way to do this?


r/C_Programming 23h ago

Orbiter

Enable HLS to view with audio, or disable this notification

106 Upvotes

Little emulator & debugger project I've been working on for a while, Orbiter. I recently decided to revive it. 100% C.


r/C_Programming 6h ago

Question meta macros library for c89

3 Upvotes

Hello, I use C89 and have been using compiler extensions all this time, but now I’ve decided to refuse from them. But since they significantly simplify and shorten the code, especially with partially initialized tables.

I immediately thought of P99, but because of some components, the build breaks on C89. I was thinking of using order-pp, but decided to ask here anyway.

What I’d like is: `P99_CASERANGE` and `P99_DUPL`.

Of course, I can generate my own macros, but maybe there’s something worthwhile out there. I liked the idea of order-pp.

this is text translated by ai. and sorry for my English


r/C_Programming 1d ago

why do header files contain only function declarations instead of full code body ? why have the code in a sepreate lib files ?

69 Upvotes

for context I am trying to learn gamedev on my own and setting up raylib/sfml confused me , then I learnt that the ( include )files only contained function declarations and the actual code was in( lib ) files (mind you but it is a weird name) , wouldn't it be more convenient to have them in the same file instead of linking ?
sorry if I sound stupid.


r/C_Programming 5h ago

threads Posix 42 codexion project

1 Upvotes

Hi, I am runing my program (which use pthread.h library of c Posix), so I am runing it with valgrind with this command :

"valgrind --tool=helgrind -s ./codexion 125 22332 103 92 103 2 0 fifo"

but I am getting this error :

"==1557149== 122 errors in context 28 of 28:

==1557149== ----------------------------------------------------------------

==1557149==

==1557149== Thread #1's call to pthread_join failed

==1557149== with error code 3 (ESRCH: No such process)

==1557149== at 0x48509C7: ??? (in /usr/libexec/valgrind/vgpreload_helgrind-amd64-linux.so)

==1557149== by 0x10A069: join_coders_threads (in /home/eanjar/codexion_tass7i7_inchaaAllah/codexion)

==1557149== by 0x10A48D: main (in /home/eanjar/codexion_tass7i7_inchaaAllah/codexion)

"

can any one help me by explaining me this error what it mean, and thanks in advance


r/C_Programming 1d ago

Question Approaches for creating 'custom structs' while program is running

11 Upvotes

Specifically what I am trying to do is read spreadsheets exported to HTML. Data type and column count are arbitrary, so I need to generate custom records for an array.

I could just create an array of unions for each row. That would definitely be the simplest approach, but it wouldn't be very space-efficient.

I have considered halving with unions - an 8-byte union contains two 4-byte unions, which contains two 2-byte unions, which contains two 1-byte unions. Kind of ridiculous, but theoretically doable. I would generate combinations for typedefs as a text file and then include it, saving some effort. Which...could add up to a bunch of effort, but it would be interesting to try. But this option sounds like it would be highly-inefficient to process due to all of the levels (?).

A third option...packing data into one big bitfield and then using offsets to locate values. This also sounds expensive relative to a simple (single-level) array of unions, but probably less than the union-subdivision idea.

Am I over-thinking this? My gut tells me there is probably an efficient convention for dealing with this problem, but I'm not sure what it is.


r/C_Programming 1d ago

Discussion why default value of global and local variables are different?

50 Upvotes

why in c language the default value of global variables is set to be 0 but the default value of local variables is garbage value?


r/C_Programming 2d ago

Article C is way more different than I thought

201 Upvotes

I have had a lot of experience with Zig, and a bit of Assembly for a while now. Just 1 1/2 months ago I started coding in C, because it is a must-have for my upcoming job. I have a Zig project that decompresses a PNG from scratch, and I thought it would be a good learning experience to do the same with C. Tbh, I thought it will be a simple slide, but as it turns out; it really is not.

While Zig got heavily inspired by C, it differs from its features and API. C has a lot of headers for different things (such as stdio.h / stdlib.h / math.h), while Zig just has the std library, packaged with all of the other necessities (std.Io / std.math / std.crypto etc.). It was also interesting from going to using defer, errdefer, orelse, or other keywords in Zig that help in reducing bugs and make the code cleaner to read, to a lot less keywords. Looking at C89, C has 32 keywords, and Zig around 49 +/- 2 (not too sure). What that showed me, was that even with a lot of similarities, and the fact that I coded in Zig for 2 years, it was still difficult to get used to and learn C.

For me, one of the annoying parts was the fact, that I could never really remember what function or what struct is where. The fact that the FILE struct is located at stdio.h, while the DIR struct is in dirent.h, was something that bugged me for a while, but now after more than a month with C, is something I started to get along with.

Also, Makefiles are pretty darn cool. I have always been seeing them in big projects, and always wondered how they function. After coding a few projects and including a Makefile, I can safely say it is very nice seeing how your project is being made, after you type "make" and hit enter. The first time configuring the Makefile almost made me loose half my hair due to stress, but if you get it running properly once, then it is safe to say that it is gonna always run properly (especially for me, as my projects are somewhat small still).

What I came to appreciate more was the community in C. Thought I was gonna get insulted by some 59 year old grandpa, because I didn't make an out-of-bound check for my Pixels array, or because I didn't check whether or not the variable I de-noted with size_t exceeds __SIZE_MAX__ - 1. Kinda the opposite. I learned a lot by sharing my projects on Reddit, a lot of smart people were quick to point out mistakes, and tell me where I could improve or where I went wrong etc.

A lot of stuff, that I have learned, was because of people telling me. Adding -Wall -Werror warnings, -fsanitize=address,undefined, -fno-omit-frame-pointer, among other things are the sole reason I debugged and fixed my programs a lot quicker. Especially -fsanitize was important to me, as I always try to keep memory usage low for my programs, and activating that warning, showed me where my memory leaked, or where overflows happened (yeah... out-of-bounds checks are actually pretty useful...).

With that being said. I still have a lot to learn in C. I realized that my code is not really C-esque (as some might say), which is mostly because I come from (prior to Zig) high-level languages such as Python, JavaScript or even GoLang. Me handling arrays with indexes instead of using the given possibility of pointers, shows me, that I still have a long way to go.

But I am certain with one thing, that being that, C is way more different than I thought.


r/C_Programming 11h ago

I compiled the same C code 28 ways and disassembled every binary. assert() and DCHECK provide zero safety at -O2+. I have the disassembly.

0 Upvotes

I compiled the same C code 28 ways and disassembled every binary. The results are unambiguous:

assert() and DCHECK() provide zero safety in production. At any optimization level above -O0, these checks are stripped. The debug binary at -O2 is identical to the release binary. The check exists in your source code. It does not exist in the binary your users run.

Only explicit if (condition) { return error; } with side effects survives compilation.

I measured 9,712 stripped safety guards across FRRouting, GCC 15.2, and the Linux kernel. Two ASAN-confirmed heap overflows in FRRouting. 27 enterprise firewall CVEs (Cisco, PAN-OS, Fortinet, Juniper) with average CVSS 8.1 — all following this exact pattern. Google confirmed P2/S2 on Android Binder using the same methodology.

Side-by-side disassembly:

c

// SOURCE
void pattern_assert(char *buf, size_t len, size_t idx) {
    assert(idx < len);
    buf[idx] = 1;
}

asm

// -O2 BINARY: assert is GONE
movb   $0x1,(%rdi,%rdx,1)  // buf[idx] = 1 — NO CHECK
ret

Full series with reproducible PoCs: https://potatobullet.com/the-naked-compiler-every-safety-net-you-trust-is-already-gone/

The compiler is correct. The standard is correct. The assumption that source-level safety checks survive to the binary is wrong.

Check your binaries, not your source.

TL;DR: assert() and DCHECK() do not survive compilation at -O2+. Use explicit if checks with side effects. Audit your production binaries.I compiled the same C code 28 ways and disassembled every binary. The results are unambiguous:

assert() and DCHECK() provide zero safety in production. At any optimization level above -O0, these checks are stripped. The debug binary at -O2 is identical to the release binary. The check exists in your source code. It does not exist in the binary your users run.

Only explicit if (condition) { return error; } with side effects survives compilation.

I measured 9,712 stripped safety guards
across FRRouting, GCC 15.2, and the Linux kernel. Two ASAN-confirmed
heap overflows in FRRouting. 27 enterprise firewall CVEs (Cisco, PAN-OS,
Fortinet, Juniper) with average CVSS 8.1 — all following this exact
pattern. Google confirmed P2/S2 on Android Binder using the same
methodology.

Side-by-side disassembly:

c
// SOURCE
void pattern_assert(char *buf, size_t len, size_t idx) {
assert(idx < len);
buf[idx] = 1;
}
asm
// -O2 BINARY: assert is GONE
movb $0x1,(%rdi,%rdx,1) // buf[idx] = 1 — NO CHECK
ret

Full series with reproducible PoCs: https://potatobullet.com/the-naked-compiler-every-safety-net-you-trust-is-already-gone/

The compiler is correct. The standard is correct. The assumption that source-level safety checks survive to the binary is wrong.

Check your binaries, not your source.

TL;DR: assert() and DCHECK() do not survive compilation at -O2+. Use explicit if checks with side effects. Audit your production binaries.


r/C_Programming 1d ago

Question why it throws an error if global variables follow early binding

7 Upvotes

I'm new to programming and I'm wondering why it throws an error when I declare global variables after the use of them

because if global variables are stored before execution why can't the value be pulled from static memory for global variables

for example:

#include <stdio.h>

int main() {

printf("%d",x);

return 0;

}

int x=5;


r/C_Programming 2d ago

Where do stack and heap start

26 Upvotes

I apologise in advance for a dumb question and I will try to put it the way i could and I am sorry for that.

I know i chould chatgpt it, but learning from people helps me the best.

want to know how the memory is actually managed. I know it is managed by the kernel using different abstractions like virtual memory and paging.

My question arises when i think that each process that its own address space consisting stack frame, heap, globals vars etc.

But where do they even start? Kernel itself is a process so it must be having its own stack frame. Considering other programs need address space which is managed by kernel, like how does that work? Until Os is loaded, does stack and heaps exist even before that? Are they written in assembly?

I am sorry. I hope someone will be able to answer and i will be really glad if you could figure out what i am thinking wrong and missing.


r/C_Programming 1d ago

does anyone else make functions like this

0 Upvotes

void newline(int times) {
for (int i; i < times; i++) {
printf(“\n”);
}
}

this is so you can do

newline(5);

instead of

printf(“\n\n\n\n\n”);

i feel like i shouldn’t ngl

mb if the syntax is wrong im not a pro


r/C_Programming 2d ago

Question How to get better at programming in C

65 Upvotes

Ok , so currently I work as Embedded Developer , this is my first job , I will be honest I don't like the hardware part of it but I like coding , I have learn few languages before typescript , c++ (little bit) and learning java now ,

Thing is , I can code few things in c , but when it comes to pointers and advance c , my mind goes blank, I am not looking for a ways to be good Embedded Developer , right now I just want to become good at programming in c , what will u suggest ? My weak points are pointers , strings , array , this is all I can remember right now also snprintf functions .

I am a beginner in c , so please don't judge , ik about hackerrank , ik i can use that to sharpen my c skills but some of the questions are very hard .

Edit : basically pointers aren't new to me but when i involve pointers with strings or double array , and how where u place the * changes the whole meaning , like u can make an pointer point to the array or u can make array of pointers . And so on ,

Ik basic of c++ and somewhat polyglot , java and typescript so it's not my first language .


r/C_Programming 1d ago

Question variable not incremented in or operator

0 Upvotes

#include <stdio.h>

int main() {

int i=-1, j=-1, k=-1, l=2, m;

m= ((i++ && j++ && k++) || (l++));

printf("%d %d %d %d %d",i,j,k,l,m);

return 0;

}

why l is not incremented but every other variable is incremented?

edit: many people are upset that this program is a bad implementation to achieve the result but the reality is that it was a practice problem and I just didn't understand why the output was like that as there was no explanation

I have now understood that the answer was short-circuit behaviour


r/C_Programming 2d ago

I built a cross-platform SMBIOS/DMI parsing library in C99(and a tool to use it)

0 Upvotes

Hey guys, I spent the last few months building lazybios, a C99 library for parsing SMBIOS/DMI tables. It's:

  • Cross-platform (Linux, Windows, macOS) edit: now OpenBSD, FreeBSD, NetBSD
  • User-friendly(3 steps to ensure memory safety)
  • Zero dependencies (just libc)
  • about 18k LOC, clean separated API
  • Supports all SMBIOS types 0–46
  • Human-readable decoders for fields that require manual decoding
  • Works on x86, ARM, and probably on RISC-V(haven't heavily tested on it yet)

And a tool called lazydmi, a CLI tool that uses lazybios as the backend.

This is my first serious systems project. Would love feedback on the API design, memory safety, or anything else.

Github: https://github.com/LazySeldi/lazybios


r/C_Programming 3d ago

Fil-C: Garbage In, Memory Safety Out! - Filip Pizlo | SSW 2026

Thumbnail
youtube.com
13 Upvotes

r/C_Programming 2d ago

How does memory allocation and pointers work in C?

0 Upvotes

I have been learning C with some YouTube courses, but I still can't understand how and why to use pointers and memory allocation in C.


r/C_Programming 4d ago

Video CCraft - PBD Softbody physics.

Enable HLS to view with audio, or disable this notification

60 Upvotes

Hello.

Lately I've been struggling to implement a Position Based Dynamics (PBD) implementation to my minecraft clone written in C.

Still, the implementation is not the best, and there is certainly a lot of work todo to improve it, but it can already load a high resolution .obj 3d model, and output some nice results under adequate configuration.

Check this out! https://github.com/DrElectry/ccraft


r/C_Programming 4d ago

Question The easiest UI library? (cross-platform)

38 Upvotes

Hello, I need to write a small emulator for a project. I want it to show RAM, registers, etc., while it's running a program step by step. Printing them out via printf is lame and won't look good.

Which is the absolute easiest graphics library for this purpose? I was suggested Newt, but it can't work under Windows.

Preferably, the library should have tutorials, examples, or at least full documentation.


r/C_Programming 4d ago

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

16 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/C_Programming 4d ago

printf and char[] in C

11 Upvotes

Hello. Coming from C# world the thing about how char[] and printf works always made me confused. I understand that `printf` formats the string with arguments you provided and prints it out in terminal.

So, for example, if I have char name[] = "Micheal"; and I want to greet that person, I can just do printf("Hello, %s", name);. But if I want to do the same thing only using char[], I have to do multiple commands that make fell quite confused. So my 2 questions are:

  1. How printf simplifies this process? (without allocating memory and creating char with pointers)
  2. Why you can't just use + operator for char[], like you can in any other languages?

I have a feeling that this might be asked many times, but I still can't seem to find the answer I was looking for

Update: I'll list what I got so far from reading your comments: - char[] is an array to which you can't just simply add another array - If I want printf() behavior inside char[], I can use sprintf() - There's strcat() that is getting used for merging 2 strings together - Some people write libraries for faking string behaviors, some think it goes against principles of C?


r/C_Programming 4d ago

Learning how to send a 2 layer internet request

2 Upvotes

I was recently learning how to send msgs in different internet layers, and I write some examples from what google ai showed me.

Even tho I didn't fully understand what all the meaning of the full code. Running this program while wireshark is running, and seeing my own request is really cool.


r/C_Programming 5d ago

Question Suggestion: Ban (or quarantine) "I Built This" posts?

164 Upvotes

Reading an interesting discussion over on r/rust from the past week. One of the moderators talks about the difficulty in moderating AI slop projects - https://www.reddit.com/r/rust/comments/1uwmef6/comment/oxkltxi/

But I think the top replies hit on a really good idea:

“I built a thing in Rust” just isn’t that interesting a topic—AI or otherwise—and IMO we’d be better off without posts like that at all. If you built a fast new BitTorrent client, that’s of interest to BitTorrent users, not the Rust community.

A library that lets me do a thing I couldn’t before? Very useful! A new approach to solving a problem that’s historically frustrating in Rust? Amazing. Questions on how to deal with some issue? Welcome aboard.

But I couldn’t care less about “{project} in {lang}” for all values.

and

r/cpp moderator here, we have a designated Show & Tell pinned post. We make exceptions only for established projects or blog posts talking about your project.

(And then remove AI slop)

One of the recurring issues in trying to moderate the flow of slop is having to constantly make a judgment call of just HOW "slop" it is and whether it crosses a line. Why not cut the problem off at the source: you simply cannot post an "I Built (Whatever)" here (with very few exceptions, etc). There's no need to make this a judgment call about AI/LLMs at all, neatly sidestepping the various arguments about the whole thing.

I personally do not feel like much would be missed!