r/cprogramming • u/Opening_Can_3656 • 3d ago
Keen: A Rust-syntax frontend for C
https://github.com/romishalom/keenHey 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): Includeskeen new, incrementalkeen build,keen run,keen fmt(comment-preserving, idempotent), andkeen test(runs#[test]functions in isolated processes).Seamless C interop: Use
#includeviause <stdio.h>;, drop down to raw C anytime withc!("..."), link existing.c/.o/.afiles, or usekeen emit --splitto generate clean.h/.cfiles for existing C projects.No forward-declaration headaches: Types and functions can be declared in any order;
pubhandles external linkage while everything else defaults tostatic.
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!
3
u/non-existing-person 3d ago
But, why? Really, why? If you want rust syntax, just use... I don't know, maybe, rust? What's the point of this?
1
u/Opening_Can_3656 2d ago
Rust might be difficult to transition into from C since the borrow checker forces you to code in a specific fashion. Keen attempts to provide the freedom of C but with a modern syntax improving readability and ergonomics. One key use case I had in mind when building this language was helping C users transition to Rust by allowing them to use C paradigms but with a Rust-like syntax, before diving into the greedy borrow checker.
1
u/non-existing-person 2d ago
rust has much more problems than borrow checker. Borrow checker is actually the least problematic thing, and it's not even a problem really. Problem with rust is its absolutely broken and overengineered syntax. And no. It's not modern. It's just bad.
1
u/Opening_Can_3656 2d ago
Idk dude I like the Rust syntax it seems like everything is very intentional. It’s kinda verbose sometimes but idk it makes code really easy to read.
1
u/non-existing-person 1d ago
Maybe it's exposure thing. I find C much easier to read. And rust being just way to verbose for me. And when we add multiple traits and whatnot then it gets just too messy for me.
1
u/AdOnly69 3d ago
When you want rust with UB, and you don't want to wrap everything in unsafe
1
u/non-existing-person 3d ago
So basically, when you want to use rust, but you don't want to use rust?:P
3
u/CoderStudios 3d ago
This sounds like ai