r/cprogramming • • 8h ago

Keen: A Rust-syntax frontend for C

Thumbnail
github.com
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/cprogramming • • 13h ago

IncHash - A disk based hash table with NoSQL ambitions.

Thumbnail
github.com
1 Upvotes

A general-purpose, header-only C99 library for Unix-like systems, implementing a disk-based, dynamically resizable, fixed-slot, (open-addressed) hash table with Fibonacci hashing (Knuth's multiplicative method), triangular probing, per-home-slot probe-bound metadata (with additional early-exit logic), partial in-place value updates (without relocating entries) and incremental rehashing, all designed for modern extent-based filesystems.

Hello fellow reddit users. Feel free to AMA about it.


r/cprogramming • • 15h ago

Coding Dragon Curve fractal using C

Thumbnail
youtube.com
10 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/blob/main/dragon-curve/dragon.c

#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();
}

r/cprogramming • • 21h ago

First person to download the game gets to give ideas for two weeks

Thumbnail
adamplpld.itch.io
0 Upvotes

If you download my game first and prove it was you, you'll get to give me ideas for two weeks. Your idea will 100% be added as long as it's realistic and possible to make. If an idea can't be done, I'll let you know where to share ideas/feedback — you can also message me on Reddit or in DMs.

Even if you aren't first, feel free to download and try it — it's not a virus, I promise. If you want, I can even record screenshots or videos showing how the game looks or how downloading works. Please, if you're the first to actually download it, reply so I know who was first (if five people download it at once, I won't be able to tell who clicked first).

Others can still share ideas too — they'll be considered, and I'll pass them to the first person (mentioning who wrote it) so that person can help decide if an idea gets added. If you suggest an idea, please explain how it would work.

If you don't speak Polish and really want something added, message me and I'll explain how the game works in English. Unfortunately, translating the game itself into English isn't planned right now because it would be tough to make. It's not a 3D game — it's a console game, and the visuals/images used are from the internet (not sure if any are AI, I didn't make them). Hope you enjoy! r/cpp r/cprogramming r/game


r/cprogramming • • 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/cprogramming • • 1d ago

How C Programming Language Was Born: The $75 Game Behind C #shorts #c_l...

Thumbnail
youtube.com
0 Upvotes

r/cprogramming • • 1d ago

Linguagem C Aula 21

Thumbnail
youtube.com
1 Upvotes

Estrutura de Controle Condicional (if de via única) em C | Desafio de Adivinhação


r/cprogramming • • 1d ago

Three free static analyzers say these small C functions are clean. Running them says otherwise.

0 Upvotes

I wrote four short C functions, each with one deliberate bug, ran clang --analyze, gcc -fanalyzer and cppcheck on them, and then ran the code under AddressSanitizer/UBSan with different kinds of input.

Results (gcc 13.3, clang 18.1.3, cppcheck 2.13, Ubuntu 24.04):

- off-by-one at exactly the buffer size: all three say CLEAN, ASan catches it on the boundary input

- negative length that passes a "too big" check: all three say CLEAN, ASan catches it

- 16-bit size truncation: only gcc -fanalyzer flags it

- use-after-free on an error path: all three find it, but cppcheck also reports a double free that never happens at runtime

The off-by-one one, for example:

if (n > CAP || len < 1 + n) return -1;

for (size_t i = 0; i <= n; i++)

dst[i] = ...;

In every case the normal input runs fine, so a test suite with only "normal" inputs would pass too.

This isn't meant as "these tools are bad". My takeaway is that a CLEAN result only covers what was actually checked: the build settings and the kinds of input. So I wrote a short note on how to report a CLEAN result together with that scope.

Everything runs in about a minute on Linux:

https://github.com/ericyunlinchiang/certify-the-checker

Question for you: which checker/flags would you expect to catch #1 and #2? If you run Clang-Tidy, CodeQL, Infer, PVS or anything else on them, I'd love to see the results. There's an issue template for that in the repo.


r/cprogramming • • 1d ago

I just released my first game, made from scratch in C. Here's how I built my own build system.

24 Upvotes

Seven years ago I decided to learn how to make a game from scratch in C and last week I finally released it.

When I started the project I wanted to write as much as possible myself from scratch. In the end that included the game engine, a Vulkan renderer, the level editor, asset pipeline and the build system. The codebase is in C style but I use the C++ compiler so I can use operator overloading for math. I don't use the standard library, exceptions or OOP.

Initially I was using CMake but I found it quite painful to work with. Whenever I wanted to update the setup of my build I had to go back to a different language and deal with something that often felt like a hack and kept breaking.

Because of this I decided to build my own tool. The build system ended up being a small program written in the same style as the rest of the game, using the same header only base library. In essence it just calls clang directly and the setup of the project is a simple fat struct.

On each run every source file gets hashed and it gets compared against the hashes from the previous build. Each source file has a saved entry in a cache that also includes the exact compiler command, so changing a flag will rebuild everything influenced by it.

Also clang generates a dependency file for every source file that lists the headers it includes. If any of those headers change, that source gets recompiled. Everything compiles in parallel and the linker only runs when something has actually been rebuilt.

This approach doesn't require having a separate configuration language or generated project files like CMake. Building only requires clang and since the build tool is just simple code, it can be debugged like the game itself. Thanks to all this adding shader compilation, bundling and code signing was quite simple. I tried doing that with CMake but I just couldn't figure out how to make it work properly.

The game I built with these tools is called Satelital. It's a 2D space puzzle game about exploring alien worlds and figuring out how their rules work. There are no explicit explanations of the puzzle rules. Instead, you gradually build up your understanding of how the world works and use that knowledge to solve new puzzles.

If you're interested in the technical side of building a game engine from scratch, I also wrote an article about it on my blog:
https://spectralorbit.com/blog/satelital_game_engine

And the game is available on Steam with a free demo:
https://store.steampowered.com/app/3256790/Satelital/


r/cprogramming • • 1d ago

Added a pure C99, Rust-inspired error handling module (<cerror.h>) to my library arstd

Thumbnail
github.com
0 Upvotes

Just added <cerror.h> to arstd (my C99 arena standard library) to bring Rust-style Result ergonomics to strict ISO C99—with zero compiler extensions (no typeof or statement expressions) so it compiles cleanly across GCC, Clang, and MSVC.

It includes typed Result wrappers, 3-arg and 4-arg TRY propagation, UNWRAP/EXPECT/UNWRAP_OR, and an optional custom error table with built-in CERROR_OK and CERROR_DEFAULT fallbacks:


CERROR_RESULT(int, ResInt);

CERROR_RESULT(const char *, ResStr);

ResInt parse_port(int port) {

if (port < 1 || port > 65535) return ERR(ResInt, cerror("ERR_INVALID_PORT"));

return OK(ResInt, port);

}

ResStr connect_server(int port) {

int valid_port;

TRY(valid_port, ResStr, ResInt, parse_port(port)); // early-returns Err on failure

// work with valid_port...

return OK(ResStr, "Connected");

}

Repo: https://github.com/mainak55512/arstd


r/cprogramming • • 2d ago

I built a zero dependencies complex linear algebra library from scratch on C99.

15 Upvotes

It has zero dependencies and is built entirely from C99 <complex.h> library. Anybody can use my library to write programs utilizing complex vector spaces be it Electrical Engineering, Signal Processing, Quantum Mechanics or even more.

I utilized single pointer flattened arrays for contiguous memory and cache efficiency.

I have included standalone example for every single function I have in my header file under the Examples/ folder.

I also built two pure C applications:

  1. Mesh Analysis on Bilateral Alternating Current Circuits to find mesh currents and power.

  2. von Neumann Quantum Entropy Calculator to measure entropy and uncertainty in qubit systems of pure and mixed probabilities.

Check out my https://github.com/CodeLeverEuler/c-complex-linalg

I'm a freshman and this is my first systems/math library in C. Would love feedback on my API design, memory contracts, or numerical stability edge cases!

Thank you
EDIT:
Some are suspicious that this is AI generated. I didn't know that was an issue. I thought I wouldn't make my repository public until it's done.
I can't share the image from my local file here. But if anyone is having second thoughts, I have timestamps on my private Git repository and local files


r/cprogramming • • 3d ago

how to make a hexdumper in c?

Thumbnail reddit.com
0 Upvotes

r/cprogramming • • 3d ago

What are some neat TUI libraries ?

Thumbnail reddit.com
3 Upvotes

r/cprogramming • • 3d ago

A simple practice(a small terminal hijacker)

Thumbnail
github.com
2 Upvotes

a basic practice, but it works quite well. It's good to attach some vim process to my current terminal. however, reptyr is totally okay though.


r/cprogramming • • 4d ago

Why are LLMs falling back to C? (Or is it?)

0 Upvotes

r/cprogramming • • 4d ago

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

Thumbnail reddit.com
0 Upvotes

r/cprogramming • • 4d ago

forbear: an immediate mode UI library that looks like the web

6 Upvotes

https://github.com/gabrielmfern/forbear

Hello! I've been working on forbear for almost 2 years now, and I've finally come around to implementing a proper C API for it! I would like to share here, and specially ask for some feedback on the API, and on how I wrote the macros that give it the DX I wanted for the library.

This is how it looks like:

void counter(void) {
    fb_s64 *count = FB_STATE(fb_s64);
    FB_ELEMENT(
        .background    = fb_color(fb_rgb(44, 49, 56)),
        .border_radius = 6,
        .padding       = fb_all_sides(8),
    ) {
        char count_text[64];
        snprintf(count_text, sizeof(count_text), "count: %lld", (long long)*count);
        FB_TEXT(count_text);
        if (fb_on_click(FB_MOUSE_BUTTON_LEFT, true, false)) {
            *count += 1;
        }
    }
}

It's a dynamically linked library, with a single forbear.h header. To try it on Linux and macOS:

curl -fsSL https://forbear.dev/quick-start.sh | sh

on Windows:

irm https://www.forbear.dev/quick-start.ps1 | iex

Beware that it's still quite experimental!

The main philosophy is to be what I envision the operating system should have provided us all along: a flexible on design, nice to write, performant, cross-language (in an idiomatic manner) and cross-platform way of making GUI programs.

I've written more about the process of making this C API here for anyone that might like to go more in depth https://www.forbear.dev/log/005-calculator-and-c-api.html


r/cprogramming • • 4d ago

How should i..?

0 Upvotes

How should i start learning C as my first language? Could anyone share some advice on where to start with C?


r/cprogramming • • 5d ago

Do you usually use printf or puts?

23 Upvotes

Sorry for the newvie question but Im interested what do you prefer to use between the two?


r/cprogramming • • 5d ago

I'm just learning C basics. Should I switch to C++ because my friend recommended it?

26 Upvotes

Hey guys!

I'm currently in my first year of college and have recently started learning C programming. I'm still at the basics stage, learning variables, data types, loops, conditions, functions, etc.

One of my friends suggested that I should switch to C++ instead of continuing with C because it's more useful and has better opportunities.

Now I'm a little confused. 😅

I want to build strong programming fundamentals and improve my problem-solving skills.


r/cprogramming • • 5d ago

New to C

8 Upvotes

I've recently been looking into C and I want to start learning it, mainly because I am interested in how it works as a low-level language after using Python for a while, and eventually plan to take on Gentoo Linux and Linux From Scratch (with prior understanding of C and compilation). I welcome any advice!


r/cprogramming • • 5d ago

At what age did you start programming, and in which language?

Thumbnail reddit.com
0 Upvotes

r/cprogramming • • 5d ago

Difference to r/C_Programming

8 Upvotes

Hello friends, may I ask what is the difference between this subreddit and r/C_Programming ?

Thanks in advance


r/cprogramming • • 6d ago

How should I start learning C programming as a first-year college student?

7 Upvotes

Hey everyone

I'm currently in my first year of college, and I want to start learning C programming from scratch.

I'm a beginner and sometimes find programming concepts confusing. I don't just want to learn the syntax or memorize programs for exams. I genuinely want to understand programming, improve my logic-building skills, and become good at writing code independently.

Also, should I focus on college syllabus topics first or follow a separate learning roadmap?

Any advice, free resources, personal experiences, or tips would be really helpful.

Thank you! I'm excited to start this journey. 😊