5.1 KiB
Perfect. I’ll use:
Project Name: C′ License: MIT Style: Developer-Friendly & Enthusiastic
🚀 Your new README.md (ready to commit)
You can copy this directly into README.md in your repo:
C′ — C with Classes. Zero Bloat.
C′ (C-Prime) is a tiny object-oriented extension to the C language. It adds classes, methods, constructors, operator overloads, inheritance, templates, reflection, and more — while still compiling to pure, readable, high-performance C99.
You write modern OOP code. C′ rewrites it into C. The C compiler does the rest.
⚡ Instant preprocessing speeds (just a few milliseconds) 📦 Tiny compiler (written in clean C99) 🧩 Drop-in compatibility with existing C toolchains 🛠 Uses TinyCC, GCC, or Clang to compile the output
Why C′?
C++ gives you a lot… and a lot of baggage.
C′ gives you just the power of classes without templates nightmares, ABI chaos, or hidden runtime behavior. Everything turns into transparent C functions and structs you can read and debug directly.
Write like OOP — ship like C.
🧠 How it works
C′ is a source-to-source compiler:
C′ source → C′ Preprocessor → Pure C output → Normal C compiler
Under the hood:
- Parse code (via custom tokenizing lexer)
- Extract classes, methods, properties
- Replace OOP syntax with C99 equivalents
- Generate
.c+.hfiles - Compile with TinyCC (or any C99 compiler)
Output remains beautiful C that you can read.
✨ Language Features
✔ Classes
✔ Methods
✔ Constructors
✔ Operator Overloading (+, +=, ==, …)
✔ Property access via this->field
✔ Inheritance (multiple!)
✔ Templates / generics
✔ Reflection
✔ SQLite3 support
✔ Console logging with automatic pretty-printing
✔ File manipulation
✔ HTTP server utilities
✔ Zero runtime dependencies
🔤 Example: Hello Classes
Input C′ code:
#include "console.h"
class application {
sayHi(char * name) {
console.log("Hi ", name);
}
launch() {
this->sayHi("John");
}
}
void main() {
application * app = new application();
app->launch();
}
Generated C:
// pseudo-simplified
typedef struct application {} application;
void application_sayHi(application * this, char * name) { ... }
void application_launch(application * this) { ... }
int main() {
application * a = application_new();
application_launch(a);
}
Readable. Fast. Pure C.
🕹 Constructors
class vector3 {
float x;
float y;
float z;
constructor(float x, float y, float z) {
this->x = x;
this->y = y;
this->z = z;
}
display() {
printf("x: %f, y: %f, z: %f", this->x, this->y, this->z);
}
}
void main() {
vector3 * v = new vector3(1.0, 0.0, 1.0);
v->display();
}
🌐 Minimal HTTP Server
#include "../http.h"
void handleRequest(struct request * req, struct text * res) {
res += "HTTP/1.0 200 OK\r\n\r\nHello from C′!\r\n";
}
void main() {
http * server = new http();
server->createServer(handleRequest);
server->listen(8080);
}
📁 Filesystem Handling
Full directory scanning + file reads/writes with class APIs.
🔧 Templates (Generics)
template<T>
class vector {
T * items;
int total;
void add(T item) { ... }
}
Compiler generates correct type-specialized C.
🧱 Multi-Inheritance
class B { ... }
class C { ... }
class A extends B, C {
...
}
Properties + methods are merged cleanly and deterministically.
🧩 SQL via SQLite3
One-liner in-memory database setup:
sqlite * sql = new sqlite(":memory:");
sql->selectModel("user");
sql->createTable();
Full CRUD built-in.
🛠 Installation & Build
Requirements
- TinyCC OR GCC/Clang
- Linux or macOS
Build
make
./cprime input.cprime
This generates .c + .h files in /output.
🔍 Internals
Lexer → Struct Model → Transform → Emit C
Lexer
⮡ Tokens
⮡ Syntax Data (structs)
⮡ Rewrite rules
⮡ Generators
The compiler itself is written in clean C99 using a tiny standard library of:
- arrays
- text utilities
- reflection metadata
- class loaders
🤝 Contributing
C′ is young — contributions are very welcome!
Ideas:
✔ Better diagnostics ✔ More docs & examples ✔ Editor syntax support ✔ Windows support ✔ More standard library components
📜 License
MIT License — do what you want, just keep the copyright notice.
⭐ Clone C′
Publicly available:
git clone https://code.kajdijkstra.com/kaj/c-prime.git
Or SSH:
git clone git@code.kajdijkstra.com:kaj/c-prime.git
💬 Final words
Thank you for checking out C′!
If you’ve ever wondered “How does a compiler really work?”
C′ is a simple but powerful place to learn — and create.
Future of C coding: Object-oriented when you want it — pure C where it counts.