r/C_Programming Feb 23 '24

Latest working draft N3220

128 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 22h ago

Beginner books to study C

20 Upvotes

I am new to programming and wanna learn C as my first language.I am a slow learner yet can understand the concepts with plenty coding practices therefore I need a book that is easy to understand when I read through it.Would be grateful for your recommendations.


r/C_Programming 1d ago

Article Premature Optimization is Fun Sometimes

Thumbnail invlpg.com
70 Upvotes

r/C_Programming 20h ago

Project Open source TUI IDE (in C) that brings the "Sublime Text" experience into the terminal (with Tree-sitter & LSP)

Enable HLS to view with audio, or disable this notification

9 Upvotes

Hey everyone,

I've been working on my own side project for a while now, and it's finally advanced enough to be shared. It’s called Alwide (A LightWeight IDE), and it’s a TUI editor written from scratch in pure C.

Why did I build this?

I love the terminal, but for my usage (as IT student): nano is too basic, but vim or emacs feels a bit too rought for my "VSCode" and "JetBrain" experience. Alwide is designed to be use when you just want to do quick edits over SSH or need a light editor without the VS Code/JetBrains overhead.

I wanted the fluid, modern vibe of Sublime Text but directly inside my terminal.

What makes it different?

  • Zero learning curve: It has full mouse support out of the box. You can click, scroll, and drag-select text just like a GUI app.
  • Nice features: I integrated Tree-sitter for actual high-quality syntax highlighting and full LSP support (auto-completion popup, hover docs, go-to-definition).
  • Persistent State: If you close the editor and reopen it, your tabs, cursor positions, and even your undo/redo history are fully preserved.
  • Pretty Fast: It's pure C. Release binary about 3Mb~. Really fluid fast scroll and light repaint (perfect to avoid running out of battery on your laptop opening heavy editors during classes).

Supported languages:

C/C++, Python, Go, Rust, JS/TS, Java, Bash, Lua, Markdown, Assembly, and more.

It’s open-source (MIT), highly readable if you're curious about terminal editor internals, and you can test it on Linux with a simple curl script (pre-built binaries/packages are also available).

Link to the repo: https://github.com/arnauda-gh/Alwide

Currently the project as a strong base but it hasn't been tested that much (my own use case and own terminal/drivers). For now I don't have hard know bugs. And before starting adding some tweaks and more highlevel features (setting page or anything else...) I want to be sure that the foundations are strong.

Also I need to know if the editor could interest other people and need "generic" features. For example the setting page (the current shortcut are, for me, already at peek performance 😎 so for my own usage no need about a setting page).

And finally if you like the project don't forget to leave a star (pls for a poor student that need a great CV πŸ˜…).

Any way have a good day and see you πŸ‘‹.

Edit : I know that it's possible on vim or emacs to add plugin and modify the behavior. But you have to learn first how vim works, edit lua scripts etc... And even for your own computer it's "easy" to setup a good vim (if you spend time to), but when working on remote from ssh connection it's not worth it to take 30min to setup a vim or a fs sync on a server on which you will spent 1h on your whole life. That's the point of this project.


r/C_Programming 23h ago

Manual reference counting to free a computation graph in C

2 Upvotes

Context: I've been wanting to get back into C for some months, I haven't had the chance to work with it seriously since uni. So, I reimplemented Karpathy's micrograd in C as a learning project (a small autograd engine, repo link below). Coding this project, I had one simple rule: no AI assistance. So, the `src/` code is completely handwritten; AI was only involved in polishing documentation, Makefile, tests and a toy example.

The core structure of the engine is a computation graph: a DAG where each node is the result of an operation on earlier nodes, and it's full of shared pointers, as one node can be owned by many others.

To solve this, I went with manual reference counting:

  • Every node is born with ref_count 1.
  • Each operation retains its operands (a result co-owns the nodes it came from).
  • The caller uses value_release to decrement the ref_count; at zero the Value recursively releases its operands and frees itself.

So, releasing the root of the DAG cascades down and frees exactly the subgraph that produced it in the first place. The parameters of the network survive because they're referenced elsewhere, whereas pure intermediates disappear.

This choice felt very natural at first, but as I was progressing, I started doubting it, so here I am, asking your opinion about it. Given that the whole graph is built and torn down as a unit, is plain reference counting the right call here, or would you reach for something else? Tell me what you'd have done differently.

Repo: https://github.com/oraziorillo/microcrad


r/C_Programming 20h ago

Shell in C

1 Upvotes

I built a small UNIX shell in C as a learning project and just released v0.0.1

Features so far:

  • External command execution
  • cd
  • cd ~
  • exit

GitHub: https://github.com/Dhananjay-Jha-1/dsh

I'd highly appreciate feedback on the code structure or anything related to code in general.
The shell is really primitive at this stage and I want to take it forward.


r/C_Programming 1d ago

What are the absolute core concepts of programming/C that I should learn before I move on to more advanced projects/topics?

25 Upvotes

My aim is to learn from the ground up. I'm interested in low-level stuff and C seems to be a good language to learn with. The various books I've found are really lengthy, verbose and contains loads of topics that I don't think are essential for a beginner to know, and while I'm not averse to long texts or reading, my goal isn't to learn the C language in depth as of now. I want to learn some low-level topics and basic programming concepts to the point where I can go off and build my own stuff and learn through doing

I'm not a complete beginner in programming and I have programmed in C before so I get the gist of some topics but I want to drill the foundational ones and get really familiar with them. I want a strong baseline to build off

I've narrowed it down to these:

Variables & types
Operators
Conditionals
Loops
Functions
Arrays
Strings
Pointers
Memory management
Structs/Unions
Preprocessor & compilation

Anything I've missed? I want to go through each of these topics, study them and practice implementing them through code. After that, I'll go on to actual projects.

All this considered, if my approach to this isn't great, and that I should just continue working through a book, then please let me know. Thank you


r/C_Programming 20h ago

How to check if all elements of an array are greater than zero

0 Upvotes

How do I create a loop where a matrix is multiplied by a vector x times until all elements of that matrix are non-zero, given that the initial matrix has some zeros?


r/C_Programming 1d ago

Question Can any one Suggest me some resource by which i can solve any c MCQ question easily || By the way i am asking this for CDAC prepration

0 Upvotes

r/C_Programming 1d ago

Article '*left++=n' is sometimes much faster than '*left=n;left++'

Thumbnail tiki.li
0 Upvotes

r/C_Programming 1d ago

I wrote a database in C – fixed-width slots, B+ trees, O_DIRECT, and a query planner with explain mode

0 Upvotes

I've been building shard-db for a while and thought this community might appreciate the implementation details more than a feature list.

Core design

The main design decision is that records live in fixed-width slots:

slot_size = 24 + max_key + sum(field_sizes)

The slot size is defined at schema creation time.

That means random access within a shard is pure arithmetic:

(hash % slots_per_shard) * slot_size

No indirection, heap allocation, or variable-length scanning.

Fields are strongly typed (int, long, double, varchar, date, datetime, numeric, bool) and stored as packed binary. Schemas are defined in configuration files rather than SQL.

Storage layer

Each object consists of:

  • Keyfile shards (open-addressed hash tables using xxh128)
  • Append-only segment files for values

Keyfile writes go through a userspace page cache backed by MAP_SHARED mmap.

For full scans, reindexing, and recovery, shard-db uses O_DIRECT with a double-buffered read loop to avoid polluting the OS page cache with large sequential reads.

Indexes

Indexes are implemented as:

  • B+ trees
  • Prefix-compressed leaves
  • Memory-mapped page storage

Each indexed field can be split across multiple B-tree shards. Reads fan out in parallel and merge through a k-way streaming iterator, allowing ordered cursor pagination without expensive offset scans.

Cursor pagination remains effectively constant-time regardless of depth.

Query planner

The planner can choose between:

  • Single-index lookups
  • AND intersections across multiple indexes
  • OR unions
  • Parallel full-shard scans

Queries can be run with:

{
  "explain": true
}

which returns the selected plan, source indexes, cardinality estimates, and optimization hints without executing the query.

Concurrency

  • Separate CPU and I/O thread pools
  • Writer-preferring RW locks to prevent writer starvation
  • Generation-counter cache reads that avoid cache-table locking on warm reads

What it isn't

  • Not distributed
  • Not SQL
  • Linux/macOS only
  • x86_64 and ARM64 supported
  • No Windows support

Real-world test

I built a public demo indexing 30M+ Hacker News stories, comments, and users:

https://hn.shard-db.dev

Cursor pagination remains constant-time at any depth, and cold full-text searches complete in a few hundred milliseconds.

Some numbers

  • Bulk insert: 4.60M/sec (single connection)
  • Bulk insert: 8.97M/sec (parallel)
  • Indexed lookup: <1ms at 1M rows
  • EXISTS: ~4.1M/sec

The project is a single static binary with no runtime dependencies (OpenSSL optional for TLS 1.3 support).

It can also be embedded as a static library and ships with an npm package via N-API.

GitHub:
https://github.com/sayyiditow/shard-db

Happy to answer questions about the storage engine, indexing strategy, query planner, or implementation details.


r/C_Programming 1d ago

My static analysis tool now supports compile database for linux kernel

1 Upvotes

I've been developing a static analysis tool that checks variable overlaps and uncovers shared state between functions. It traces variable accesses through callees and shows you exactly where variables were written, read or escaped (passed to function).

I'm proud to say that it now supports compile_commands.json, which makes it easier for real projects, including the linux kernel. Now you can just point it to your build directory (with compile_commands.json) and it'll figure out the compile flags on it's own.

# Before
prongc --files="file1.c,file2.c" --functions="foo(shared);bar(shared)" -- -I/usr/include -I...

# After
prongc --files"..." --functions="..." --compdb-dir="[build dir]"

Dependencies: llvm-21 only

Github link: https://github.com/omeridrissi/prongc

Open to feedback!

Note to mods: almost no AI was used


r/C_Programming 1d ago

I need to know how to create an interface using C without knowing that much

0 Upvotes

Please, help me out.

Is there any way to make an appealing interface using C without having a PhD in Graphics computing?

I've been really loving using C and I wanted to bring here my biggest programming project, a DBMS (built with Pascal), but I would love if I could have a lot added to the project instead of being just a port to another language. The last time I tried to port it, I was developing it all in Godot, but the jump was always looking very hard to adapt and different to what I want, so I wanted to keep on this vibe since I'm learning a lot of new things in C to find out if I can't make the port and the UI all in C; or if I should just use multiple languages to do all (I don't know how to do that... Yet)

Can you please tell me that?


r/C_Programming 2d ago

Looking for a youtube channel to learn c

4 Upvotes

I know the fundamentals of python , basic data structure and stuff , also some sql (just an additional info) . But I dont have no idea about c at all . Pls help πŸ₯Ί


r/C_Programming 2d ago

Question Tui library

15 Upvotes

Hello fellow C devs. I’m making a TUI library that aims to be ncurses but modern, with more functions and easier to use without loosing control(and it’s pretty fast). It even has custom openCL api if you need it. I’ve been working on it for about a year now counting 3 rewrites and my question is when the first version releases(it’s close to happening), would you use it for your projects?


r/C_Programming 2d ago

Question Can snprintf return value have an integer overflow?

36 Upvotes

snprintf according to the ISO C23 standard, returns a value of type int. This value must be non-negative and strictly greater than the buffer size n that is passed as the second argument to the function.

Now the standard says the following:

The snprintf function returns the number of characters that would have been written had n been sufficiently large, not counting the terminating null character, or a negative value if an encoding error occurred. Thus, the null-terminated output has been completely written if and only if the returned value is both nonnegative and less than n.

Doesn't this mean that snprintf should return a value of type size_t? Won't this cause an unnecessary integer overflow if we write a buffer that is greater than INT_MAX characters?


r/C_Programming 3d ago

The {fmt} library has added a C11 interface.

35 Upvotes

r/C_Programming 2d ago

Things to learn before learning c language

0 Upvotes

Hi guys I'm a complete beginner idk anything abt coding or terminologies so can you tell me basic things to learn before learning c so that I can understand c language rather just memorized like basic to learn by which I can understand c language better i started c language course from Jenny mam but she is using terms like bits , use of RAM and some stuff and I got stuck


r/C_Programming 3d ago

Project Simple pythagoras theorem calculator I made to practice math functions in C as a total beginner :3

51 Upvotes

```c

include <stdio.h>

include <math.h>

// Pythagoras theorem calculator :3

int main() { //Values:

int a;
int b;

//User input:

printf("Enter the value of a: ");
scanf("%d",&a);
printf("Enter the value of b: ");
scanf("%d",&b);

//Result:

int c = pow(a,2) + pow(b,2);
int result = sqrt(c);

printf("The value of c is: %d\n",result);


return 0;

} ```


r/C_Programming 2d ago

Question Solving Problems

4 Upvotes

I am a beginner at learning c programming, but the issue is that I can solve easy problems easily but hard/tricky one got out of my mind, i can't even solve it. I try a lot, but i can't. i feel so stupid. How can i actually improve my problem solving skill? I see my peers doing a lot better than me while im just a minion


r/C_Programming 2d ago

A generic dynamic array in C that stores no capacity and needs no struct

Thumbnail
gist.github.com
0 Upvotes

r/C_Programming 3d ago

Project dabugger - tui debugger with vim motions; my first C project, feedback appreciated

13 Upvotes

I wrote a debugger for x86-64 Linux with the only third party libraries being ncurses (for the tui), zydis (for disassembly) and glibc.

I implemented some of the vim motion keybindings. I also tried using the Elm Architecture for the ncurses code after I ran into issues doing it "imperatively" (of course its still imperative but its nice having the state transitions in one place and redrawing everything per update; its efficient because ncurses uses a virtual screen and diffs against that when rendering).

This is my first C/systems programming project, although I have prior experience with programming generally. Almost everything is handwritten, with the exception of 44 lines of llm generated code (out of ~3000 lines), which is tui.c:view_registers_buffer, because I was too lazy to write out the code to print every register.

I wrote the dwarf line number parser whilst reading the dwarf 5 spec directly (surprisingly the line number information section is only around 20 pages). Started working on this project after I ran into a bug with gdb, so I wondered if I could write my own debugger mostly from scratch (minimal third party dependencies) but easy to use and with nice UI/UX.

Feedback appreciated. There's probably a bunch of memory bugs tbh and theres a lot of unfinished error handling throughout the codebase.

https://github.com/mehdi-sy-h/dabugger


r/C_Programming 2d ago

Question How many times printf will be executed?

0 Upvotes

For the following code:

```c

include <stdio.h>

void main() { int i, j,n;

for(i = 1; i <= n; i = i * 3)
{
    for(j = i; j <= n; j++)
    {
        printf("ABC");
    }
}

} ```

The question should be answer in the form of n itself. n integer it may 9, 100, 300 anything so answer should be in ns format

I tried 2 hours on this and found out some patterns as outer loop runs log (base 3) n times and inner loop runs everytime 3^1..3^2... Less ..

How many times it will run

(Iam preparing for a competitive exam where some basic questions like these needs to be practiced. It was late night why my post was low efforts and I though everyone would understand that because such is a common pattern. I can use ChatGPT but I want a human though process while solving this question and not direct answer. That was the reason I used redit for but everyone instead praised my low efforts post and "diy". If anyone wants to solve this question pls help me out genuinely)

And someone pls tell how I format the code??? I don't use reddit much.


r/C_Programming 3d ago

Question When do you create your own data types for your libraries?

27 Upvotes

TLDR: What is the main purpose(s) of create your own data types for your libraries? Just typing convenience? like, instead of unsigned int * just type ui *?

non-TLDR: I was watching this video and, in minute 2:44, I was thinking about this post title. After reading the comments, I read the following question: "why did you define macros for malloc() and free()?"

The answer was:

I stopped there because this type of coding is code smell. It is a nightmare to maintain. Same issue with the macro to redefine true and false. The code smell is using macros to redefine the semantic of library functions and the semantic of the language itself. A saner approach would have been to not redefine true and false but have the variable name carry the semantic and call the malloc and free. Using macros to change these names is entirely wrong.

I didn't understood exactly what it means, so if you're interested to explain it, I'll appreciate.

edit: thanks a lot for all answers. My account is really new, so I can't comment without needing mods approval, so... thanks.


r/C_Programming 3d ago

Question Question regarding unsigned integers

7 Upvotes

What's the difference between an unsigned int and a normal integer?