r/C_Programming • • Feb 23 '24

Latest working draft N3220

134 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-11-18

3 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 • • 4h ago

Video Brian Kernighan: Inside Bell Labs, The Best Programmer, Why C Won

12 Upvotes

Interesting video by Ryan Peterman:

https://www.youtube.com/watch?v=sMllOlxVgD0

Timestamps: 
1:21 C was always the fastest.
1:22 C++ wasn't as fast as I thought it would be.

00:00    Intro 
00:42    What Bell Labs was and how he got hired 
06:34    Why so many inventions came from Bell Labs 
14:15    A day in the life at Bell Labs 
27:55    The most impressive people he worked with 
33:50    The AT&T film explaining Unix 
39:46    Why C was so influential 
43:25    How awk was created 
48:40    What he misses most about Bell Labs 
54:10    Are LLMs bad for computer science education 
01:01:46 His 1972 commit in the Go repo 
01:03:43 Grace Emlen, the fake Bell Labs employee 
01:07:39 Why he writes so many books 
01:19:58 His favorite and least favorite languages 
01:24:28 Advice for students and young people 
01:27:42 Outro

r/C_Programming • • 15h ago

Coding Dragon Curve fractal using C

Thumbnail
youtube.com
24 Upvotes

In this video, I code a Dragon Curve fractal using C and Raylib.

The approach is quite simple:

I take the last point as a pivot, then rotate the remaining points 90 degrees around it. Finally, I connect the new points to create the next iteration of the fractal.

Source code:
https://github.com/FractalCodeRicardo/zen-programming/tree/main/dragon-curve

#include <stdio.h>
#include <raylib.h>
#include <raymath.h>

#define linesSize 90000
#define lineSize 2

typedef struct {
  Vector2 p1;
  Vector2 p2;
} Line;

void DrawLines(Line lines[], int s) {
  for(int i = 0; i < s; i++) {
    Line l = lines[i];
    DrawLine(l.p1.x, l.p1.y, l.p2.x, l.p2.y, WHITE);
  }
}

Vector2 rotate(Vector2 p, Vector2 rp) {
  Vector2 d = Vector2Subtract(p, rp);
  Vector2 r = Vector2Add(rp, (Vector2) {-d.y, d.x});

  return r;
}

int AddLines(Line lines[], int s) {
  if (s * 2 >= linesSize)
    return s;

  Vector2 rp = lines[s-1].p2;
  int newSize = s - 1;
  for(int i = s -1; i >= 0; i--) {
    Line l = lines[i];

    Vector2 p1 = rotate(l.p1, rp);
    Vector2 p2 = rotate(l.p2, rp);

    newSize++;
    lines[newSize] = (Line) { p2, p1};

  }
  return newSize + 1;
}


int main() {

  Line lines[linesSize];
  int s = 1;
  float center = 900 / 2.0;

  lines[0] = (Line) {
    (Vector2) { center, center}, 
    (Vector2) { center + lineSize, center}, 
  };

  InitWindow(1500, 900, "Dragon curve");

  while(!WindowShouldClose()) {
    BeginDrawing();
    ClearBackground(BLACK);
    
    if (IsKeyPressed(KEY_SPACE)) {
      s = AddLines(lines, s);
    }

    DrawLines(lines, s);
    EndDrawing();
  }

  CloseWindow();
}

AI Disclaimer:
No AI was used.


r/C_Programming • • 9h ago

Review [API review] Looking for feedback on ergonomics and clarity of a unit test library.

1 Upvotes

Hello, I'm working on a unit test library. I've come to the point when library starts to work, and I would like to get your feedback on its ergonomics. It's still missing some features, but the core functionality is ready. Please let me know what could be improved, or which areas should I explain clearer in examples.
Repository: https://codeberg.org/KOOBAS/UltimaTest

There are examples included in the repository, that shows the library capabilities:
01 - shows how to create suites and tests
02 - shows how to use asserts/expects
03 - shows how to use mocks
04 - shows how to use test options to handle signals

I don't expect you to dive into the whole codebase. Focusing on the public API and examples would be really helpful. The only public header is the "include/ultimatest.h".

Here is how the library could be used (it's simplified example from my other project):

#include <ultimatest.h>
#include <widget.h>
#include <screen.h>
#include <context.h>

void widget_suite_prepare(void)
{
  struct Widget *widget = ut_test_data(sizeof(struct Widget));
  widget->type = TYPE_EMPTY;
  widget->order = 0;
  widget->position.y = 0;
  widget->position.x = 0;
  widget->size.h = 10;
  widget->size.w = 20;
}
TestSuite(widget_suite, .prepare = &widget_suite_prepare);

Test(widget_suite, move_widget_should_return_error_if_widget_is_null)
{
  ut_assert_eq(widget_move(nullptr, 4, 4), ERROR);
}

Test(widget_suite, move_widget_should_change_its_position)
{
  struct Widget *widget = ut_get_test_data();
  int new_y = 5;
  int new_x = 7;
  ut_assert_eq(widget_move(widget, new_y, new_x), OK);
  ut_assert_eq(widget->position.y, new_y);
  ut_assert_eq(widget->position.x, new_x);
}

Test(widget_suite, resize_widget_should_return_error_if_size_is_negative)
{
  struct Widget *widget = ut_get_test_data();
  int old_h = widget->size.h;
  int old_w = widget->size.w;
  ut_assert_eq(widget_resize(widget, -1, 30), ERROR);
  ut_assert_eq(widget->size.h, old_h);
  ut_assert_eq(widget->size.w, old_w);

  ut_assert_eq(widget_resize(widget, 30, -1), ERROR);
  ut_assert_eq(widget->size.h, old_h);
  ut_assert_eq(widget->size.w, old_w);
}

Mock (void*, malloc, size_t);
Mock (int, getmaxy, WINDOW*);
Mock (int, getmaxx, WINDOW*);

Test(context_suite, init_should_create_screen_array_and_buffer)
{
  const int max_y = 5;
  const int max_x = 10;
  const int screen_num = 5;
  expect_call(ut_will_return(max_y), getmaxy, ut_any);
  expect_call(ut_will_return(max_x), getmaxx, ut_any);

  size_t buffer_size = sizeof(cchar_t) * max_x * max_y;
  size_t screen_size = sizeof(struct Screen) * screen_num;

  expect_call(ut_will_return(ut_test_data(buffer_size)), malloc, buffer_size);
  expect_call(ut_will_return(ut_test_data(screen_size)), malloc, screen_size);

  struct Context context;
  ut_assert_eq(context_init(&context, screen_num), OK);
  ut_assert_gt(context.size.h, 0);
  ut_assert_gt(context.size.w, 0);
  ut_assert_ne_ptr(context.screen, nullptr);
  ut_assert_ne_ptr(context.buffer, nullptr);
}

Also, please let me know if the namespace is polluted by my prefixes or if the log messages or error messages are unclear.

AI usage: Only as googling tool (when searching for documentation, examples, etc. or discussing ideas). No code in the repository was generated by AI.


r/C_Programming • • 21h ago

Looking for the final chapter of the first edition of Practical C Programming (1991) by Steve Oualline

5 Upvotes

Hello everyone,

I'm trying to find some information about the original first edition (1991) of Practical C Programming by Steve Oualline, published by O'Reilly.

In the second edition, the author mentions replacing the final chapter with a different project. If I remember correctly, the original chapter contained a fairly substantial programming project involving probability distributions, possibly the Poisson distribution.

Unfortunately, I haven't been able to find a copy of the first edition or a detailed table of contents.

Does anyone happen to own this edition, remember its final chapter, or have access to a copy?

I'd particularly appreciate knowing the title and subject of the original final chapter.

Thank you!


r/C_Programming • • 1d ago

Question Can I learn C while learning low level concepts

20 Upvotes

Im just starting out programming, I got familiar with python. But I want to get into system programming. I know that I should learn low level concepts and data structures, I got books to read up on it but I'm just wondering if I can learn the language while learning the essentials to c programming... Sorry if this is a stupid question


r/C_Programming • • 1d ago

How I handle single-character user input in C:

0 Upvotes

When reading a single character in an interactive terminal program, I avoid scanf, getchar, and fgetc. Instead, I use fgets() and isolate the character by using unsigned char result = n[0];.

I actually use fgets for all user inputs.

The example below converts keyboard characters to hexadecimal numbers.

#include <stdio.h>
#include <string.h>

void flush() {
    int clear;
    while ((clear = getc(stdin)) != '\n' && clear != EOF) {
    }
}

void charHex() {
    char n [3];
    printf("Enter a character (one byte max), or 'xx' to exit:\n");
    while(1) {
        if(fgets(n,sizeof(n),stdin) == NULL) {
            clearerr(stdin);
            printf("\nInvalid input.\n\n");
            continue;
        }
        n[strcspn(n,"\n")]=0;
        if(strlen(n) >=2) {
            flush();
        }
        if(strcmp(n,"xx")==0){
            break;
        } else if(strlen(n) == 0) {
            printf("\nEnter a character only.\n\n");
            continue;
        } else if (strlen(n) >1) {
            printf("\nEnter no more than one character.\n\n");
            continue;
        }  
        unsigned char result = n[0];
        printf("0x%02x\n",result); 
    }
}

int main() {
    charHex();
return 0;
}       

r/C_Programming • • 22h ago

Help me

0 Upvotes

Guys I have question,

How the fuck can I learn c program in 5 days because my exam is coming in 5 days I m absolutely dumb guy and I don't have laptop as well as I m stroke patient since last 2 years where our 9 to 5 schedule is fully pack so I don't go in college and I don't have c language book as well I also want to learn matrix algebra, buisness mathematics, electronics their papers are also coming and I only their chapter

No student contact

No teacher contact

Only me and my fucking phone and you peoples

Please help me

(Btw I m doing graphic course in rehab because they provide us so that means I have 2 course 🥀😭 help meeeee)


r/C_Programming • • 1d ago

Keen: A Rust-syntax frontend for C

0 Upvotes

Hey everyone,

I’ve been working on Keen, a language that gives C a modern, Rust-inspired syntax and Cargo-like tooling without changing C’s underlying semantics.

The core idea

Keen changes C’s syntax only. There is no borrow checker, no type checker, and no safety enforcement. All of C’s rules (integer promotion, ABI, linkage, UB) remain completely intact. Keen transpiles .kn files to C, hands them off to gcc or clang for semantic checking and compilation, and maps compiler diagnostics directly back to your .kn source lines via #line directives.

It's aimed at C developers who want modern ergonomics (modules, match, for i in 0..n, no header boilerplate, built-in testing/formatting) without giving up C's simplicity, or C devs looking to get comfortable with Rust's syntax before tackling the borrow checker.

What a quick example looks like

use <stdio.h>;

struct Point { x: f32, y: f32 }

impl Point {
    pub fn len2(p: *const Point) -> f32 { p->x * p->x + p->y * p->y }
}

pub fn main() -> i32 {
    let p = Point { x: 3.0, y: 4.0 };
    printf("%.1f\n", Point::len2(&p) as f64);
    return 0;
}

What’s included out of the box

  • Zero-dependency toolchain (whet + keen): Includes keen new, incremental keen build, keen run, keen fmt (comment-preserving, idempotent), and keen test (runs #[test] functions in isolated processes).
  • Seamless C interop: Use #include via use <stdio.h>;, drop down to raw C anytime with c!("..."), link existing .c/.o/.a files, or use keen emit --split to generate clean .h/.c files for existing C projects.
  • No forward-declaration headaches: Types and functions can be declared in any order; pub handles external linkage while everything else defaults to static.

Try it out

GitHub: https://github.com/romishalom/keen

I'd love to hear your thoughts on the syntax mapping, edge cases with C interop, or what features you'd want to see next!


r/C_Programming • • 2d ago

Query on usage of restrict keyword in passing pointers

19 Upvotes

The following piece of code is doing the rounds on X as John Carmack's code which computes sin and cos from a table instead of at runtime.

#define ANGLETOFINESHIFT 19
void MoveActor(fixed_t *x, fixed_t *y, angle_t a, fixed_t speed) {
    int idx = a >> ANGLETOFINESHIFT;
    *x += FixedMul(speed, finecosine[idx]);
    *y += FixedMul(speed, finesine[idx]);
}

My query is, why aren't x and y declared restrict to denote that they point to different fixed_t ? Presumably the code is meant for sheer speed and would not usage of restrict allow the compiler more optimization? For e.g., say, parallelization of *x and *y updates in a tight loop?


r/C_Programming • • 3d ago

Video Let's spawn the HERO in C programming : 07 | NO-AI

Thumbnail
youtube.com
74 Upvotes

This video is part of my "Let's build a JRPG Game in C programming (SLD3)". Today we are going to spawn the Hero character in our Tiled map and render spritesheet.

(it all started in 2019 with GoLang as a hobby https://www.youtube.com/watch?v=yZpoXFUG6nc Now I'm moving to C, but a step by step tutorial for everyone).

Full Playlist here: https://www.youtube.com/playlist?list=PLWiIuxEJy4_c

Handmade code, NO AI USED. Video is also 100% unedited, except for overview section.

Please do subscribe, I really appreciate any feedback. \m/


r/C_Programming • • 2d ago

Portability of Programs written using miniaudio vs pipewire

6 Upvotes

I know that miniaudio doesn't have any dependencies to compile, I was just curious whether that meant that it had no dependencies other than pipewire & ALSA on the system it would run on. Would using pipewire make the program any more portable or would the benefit just be efficiency(in the case that you can "beat miniaudio" in terms of efficiency, or perhaps dont need all of its features)?

EDIT: I forgot that some people use audio not on linux for some reason lol, I was more curious about whether different distros have different dependencies. but the answer seems to be that miniaudio is cross-platform and pipewire is not


r/C_Programming • • 3d ago

Discussion 1 year With No AI

37 Upvotes

As a beginner in programming who is interested in low-level programming, I think I should avoid Ai for at least a year

because I believe that at the high level and in large-scale projects, you won’t even be able to get started without a high level of problem-solving skills and an understanding of architecture and engineering.

So I’d like to hear your thoughts, because we beginners know that learning to program the traditional way is important, but the temptation of AI is strong and distracting.

What do you think?


r/C_Programming • • 3d ago

Which IDE would you recommend?

13 Upvotes

I'm a beginner in C and I'm not sure which IDE to choose there are so many options. I currently develop on Windows, but I'm switching to Linux for better optimization and more control over my system. What would you recommend as the best IDE? Also, to learn C effectively, I'm using OpenClassrooms and an app called Coddy. I accept every piece of advice!!


r/C_Programming • • 2d ago

Article What actually happens to your C code inside GCC: a stage by stage trace of one small program

4 Upvotes

Blog post: https://www.satvikcode.com/blog/why-do-compilers-need-so-many-intermediate-representations

well, i always wondered what GCC really does with my C code so I took a small function and dumped every stage with -E, -fdump-tree-*, -fdump-rtl-*, -S and objdump on a GCC 16.1, ARM mac.

Btw a few things that surprised me here like -

- with -O2 the whole call calculate(5, 7) disappears and main becomes just "mov w0, 19"

- the if statement turns into a branchless csel instruction meaning no jump at all

- sum * 2 becomes a left shift

- why the parentheses in a function like macro actually matter shown in the preprocessed output

Btw here's an AI disclosure: I ran every command myself and all the outputs in the post are real and unedited GCC output. I used a little AI to help me understand the dumps and write up the explanations roughly and then I edited and gave them the current shape.

Next post will trace the same program through clang or llvm. and happy to hear corrections.


r/C_Programming • • 3d ago

Question What are some neat TUI libraries ?

25 Upvotes

So I'm trying to do a TUI application for fun, and I wanted to use C for a change (I love the language but almost only used it for embedded devices/drivers, stuff like that so no UI work)

The project it would be used on is a TUI solo TTRPG toolset (dice roller, note editor, etc.)

I know about ncurses obviously, and notcurses as well, but I was wondering if there was any other library you could propose so that I had a look before settling on something.

I'm open to all proposition, it's mostly curiosity and just for a small hobby project, thanks in advance!

Edit: thanks for the answers, looking at everything I think i'll give termbox2 a go and see how it goes!


r/C_Programming • • 4d ago

Starting systems programming on my Fedora with C. Where should I start?

18 Upvotes

I'm on Fedora and I want to learn systems programming properly. I know python and some c++. What's the best first step, and what should I avoid as a beginner?
Thanks


r/C_Programming • • 4d ago

C's designated initializers give us named arguments – Arthur O'Dwyer

Thumbnail quuxplusone.github.io
48 Upvotes

r/C_Programming • • 3d ago

Question how to make a hexdumper in c?

0 Upvotes

i want to use ansi-c (c89) for this project,

my skill level; read chapter 1 t/m 4 k&r v2 and knows other programming languages.


r/C_Programming • • 4d ago

Question Can you use your own implementations of HTTP/WebSockets in a browser using wasm?

8 Upvotes

Hello,

I wanted to make my own network stack implementation (http and websockets) just for learning purposes, so my question is knowing that were using sockets can we use that in the browser after compiling to a wasm? Or will it only work natively without serving to a browser?


r/C_Programming • • 5d ago

Building a small C99 compiler to get better at low-level C and x86-64 assembly

15 Upvotes

Hey everyone,

I've been trying to deepen my understanding of C and x86-64, and instead of just doing LeetCode or toy projects, I decided to try writing a tiny, self-contained C compiler in C99.

I wanted zero external dependencies just standard C library headers (stdio, stdlib, string, ctype).

I just reached the milestone where it handles operator precedence and nested parentheses:

  • Tokenizer: A linked-list tokenizer with character pointers that skips whitespace and formats visual Clang-style ^ caret error diagnostics.
  • Parser & AST: A recursive descent parser that allocates binary AST nodes for operators and numbers.
  • Code Generation: A stack-based code generator that recurses through the AST and emits x86-64 assembly (using push/pop for expressions, imul for multiplication, and cqo + idiv for signed 64-bit division).

Writing this has already taught me so much about memory layout, pointer arithmetic, and how the Linux ABI handles return values in %rax.

I have a test script with automated GitHub Actions CI verifying each arithmetic edge case against GCC.

I'd really appreciate any C veterans taking a look at my C style, error handling, or memory management in src/main.c:

https://github.com/mi-vault/mibicc

Any tips or feedback are very welcome!

Edit: Decided to add Windows support alongside Linux from the start (--target=windows and --target=linux). I'm on Windows myself so it felt silly to only target Linux System V and not be able to test it locally. Also feels nice putting my own stamp on it rather than just following chibicc 1:1.

(Had some great discussions over on r/Compilers about ABI quirks and stack architectures if anyone is interested in that side of things!)


r/C_Programming • • 4d ago

Question I need help understand what a question is asking me to do in uni exercise

1 Upvotes

I can't post an image to it, but it says in normal arrays : declare 3 arrays A, B, C all of size 5

The elements of C are the scaler products of A and B (∑︁A[i] × B[i])

And in 2d arrays :

C is there product, (matrix multiplication : C[i][j] = sum of A[i][k] * B[k][j] )

Can someone explain to me what they asking to make


r/C_Programming • • 4d ago

Building a user space network stack from scratch

0 Upvotes

I dont know much about networking as i am just now studying it seriously but i am thinking of building what i mentioned in the title from scratch, if anyone could help me with the direction im supposed to go in to start i would really really appreciate it. whenever i try looking up a place to start all i get is github repos with many many files of stuff im not yet familiar with and it all assumes prior knowledge of some stuff, i know you cant really just go into this thing blind but what im saying is i dont really know where to begin learning about all of this stuff to build my target. also i am on a 2-week time limit