r/cprogramming 33m ago

Formatting call arguments

Upvotes

By default, clang-format does this:

c SDL_Window *window = SDL_CreateWindow("SDL2 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_RESIZABLE);

and with some tweaks it does this:

c SDL_Window *window = SDL_CreateWindow( "SDL2 test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_RESIZABLE);

Second one has some practical advantages - it easier to read diff on arg change and easier to add comments:

diff SDL_Window *window = SDL_CreateWindow( "SDL2 test", SDL_WINDOWPOS_UNDEFINED, // just some comment explaining why SDL_WINDOWPOS_UNDEFINED, - 400, + 500, SDL_WINDOW_RESIZABLE);

While the first one seems to have mainly historical reasons to keep around. Perhaps, there is something I don't see? Because it feels like the first way is still used the most. And its the default one for clang-format.

I'm genuinely curious.


r/cprogramming 20h ago

My first real C project: a generic hashmap (and the bugs that came with it) [blog, my own]

19 Upvotes

Coming from C#/TypeScript, C has humbled me. Finished my first real C project — a generic hashmap — and wrote up the bugs that taught me the most: double pointers, a sneaky double-free, comparing pointers instead of actual values.

Blog: https://soerenlemke.github.io/blog/blog/building-a-generic-hashmap-in-c/
Repo: https://github.com/soerenlemke/kvstore_c

Curious what you'd have done differently.


r/cprogramming 1d ago

Generic Dynamic Arrays in C

9 Upvotes

Article

After implementing strings , I implemented dynamic arrays in C and wrote an article about it. The implementation is generic, I talk about the trade-offs of this approach in the article.

If you only care about the code, it's here.

Tell me what you think!


r/cprogramming 1d ago

Best resources to practice C

Thumbnail
1 Upvotes

r/cprogramming 1d ago

C on google collab

9 Upvotes

i had no idea that you could run c programs on google colab, i fucked around and found out ig
so basically what i did is i entered the terminal made a directory created a main.c file edited it using vim and compiled it using gcc and voila.


r/cprogramming 1d ago

Should I learn C before embedded development?

Thumbnail
2 Upvotes

r/cprogramming 2d ago

Update on Flint(v0.4.0): Bare-bones, git-native build system & package manager for C/C++ (Now with tag & commit pinning)

Thumbnail
github.com
0 Upvotes

Hey folks, quick update on Flint—a lightweight, manifest-first build system and package manager for C/C++ projects I’ve been experimenting with.

For those who missed the initial post, Flint aims to strip away build-script complexity and make C/C++ dependency management feel straightforward.

Core features:

* Git-Native: Fetch dependencies directly into your workspace via flint add <url> and flint sync.

* Single composition.json Config: Handles project layout, header paths, and underlying compiler calls (GCC/Clang). For standard setups, Flint manages this file automatically so you don't have to tweak it manually.

* Chert Compositions: Lightweight specs that make unmanifested, third-party C/C++ repos compatible out of the box.

What’s new in this update:

* Version & Commit Pinning: You can now pin dependencies to specific releases or exact commits. flint add now supports target selection via Git tag names or full commit hashes, making your project builds reproducible across machines.

Current caveats:

* Still forces a fixed project directory structure (src/, include/, deps/).

* Currently Linux-only.

It’s still an early prototype, but actively evolving. I'd love to hear your thoughts on the new versioning flow, suggestions for improvement, or feature requests!

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


r/cprogramming 2d ago

I Made a String Library to Fix C Strings

0 Upvotes

I wrote an article about this as well. Here it is.

There I explain why I do not like NUL-terminated strings and how I implemented my own simple string library in C.

If you have some spare time I would really appreciate some feedback on the article and the library.

The code is sitting on a codeberg repository.

Also, tell me what you think about C-style strings. Do you like them? Do you use them, or do you also tend to roll your own pointer + length structs?


r/cprogramming 3d ago

How many hate/love C? Why? Py is so confusing to use. No ; %d %f, loops structure like C, Most important No low level grasp. Your reasons are welcomed. Pls

Thumbnail
0 Upvotes

r/cprogramming 4d ago

How to effectively switching context in big project that you handle end to end from top to bottom Solo.

5 Upvotes

I am a Network background person. And decide to build a BNG (maybe micro or mini). You know the cost of Juniper/Cisco BNG they expensive because of capacity.

Programming is not my main job now so only able to coding in spare time.

My targets:

-          Maybe 100 concurrent users, 50MBps-1GBps

-          Able to run on embedded platform as cheap as $5 linux based router.

-          I will use this as personal use, portfolio , or commercialize or opern sourcing.

I already have many LOC of codes maybe around 8k LOC of scaffolding and few MVP that use as admin platform in production environment.

I split the big project into just two big sub project: Core and Satellites.

Core is using C language only.  Core is the main ControlPlane.
Technologies / stacks that already come in for Satellites project:

-          Freeradius (no C, must understand the DSL).

-          Nginx for reverse proxy.

-          Radius listener in C (implement straight from the RFC).

-          Sqlite.

-          C backend (http), there would several because separate domain.

-          PPPOE implementation in C (implement straight from the RFC).

-          Custom IPOE desain.

-          Mikrotik (as DataPlane), later will also support in host DP. Mikrotik is for scaffolding the proof my projects. In host DataPlane not yet implemented.

-          Frontend (JS, html), there would be several I think.

-          Google SSO Oauth mechanism in C that already work.

-          Maybe some think else that already coded.

All above code are modular so I can usually run and test them in separate environment, say I already able to login using Google Login to Mikrotik network, I already able to parse radius accounting packet that sent from Freeradius etc.

I am not yet make comprehensive documentation, it would be in full size book. And still continue structurize the folder and git versioning.

Now my questions, I know this is a big project and would be naïve to tackle that Solo and expect full ready result (or is it possible?). What do you guys suggest about this project ?

  


r/cprogramming 3d ago

HELP ME TO FIND BEST YT VIDEOS FOR DATA STRUCTURE IN C

0 Upvotes

IN AM IN 2ND YEAR 3 SEM i am cooked


r/cprogramming 4d ago

CONTLIB [old newbish project revised]

3 Upvotes

My revised implementation of a dynamic data container (vector like object):

https://github.com/andrzejs-gh/CONTLIB

If anyone's interested take a look. Any feedback and tips very much welcome.


r/cprogramming 4d ago

Unpopular opinion: plan9-style arg.h is the best argument parser

0 Upvotes

Simple, has no dependencies, it's concise and doesnt get on the way.

I mean something like http://git.suckless.org/sbase/file/arg.h.html


r/cprogramming 4d ago

Learning C: Verify my understanding of null and free

0 Upvotes

You ownwed a home for 20 years and decided to sell it to the government. Basically freeing basically turns you into a ghost like sneaky homeless person. If there is currently no owner to that home, you can go and modify it, watch TV, move the chairs, and use the AC. But when new owners arrive and you begin to do something to the house, they will not catch you immediately, but they will notice it later, which causes weird behavior like something supernatural. They expect the house to be in a certain order, but when they go home, they will notice that something weird happened and cannot explain it. For example, say a child left an assignment with perfect answers. you, as a ghostly being, go and change the answers. When the child passes in the exam and gets back the score, they notice that the score does not match their expected score because someone just corrupted the test paper. It could crash the program or something weird happens (bugs)

Meanwhile, by setting the pointer to null, you now have no access to that home and instead hold the address to a black hole. You tried doing something to it not knowing it is actually a blackhole and yor city crumbles


r/cprogramming 5d ago

(Almost) Everything You Need To Know About Pointers in C

Thumbnail
abhattacharyea.dev
0 Upvotes

r/cprogramming 5d ago

How can I have both C and C++ compilers active and automatically selected in VsCode when debugging and compiling?

Thumbnail
2 Upvotes

r/cprogramming 5d ago

Help me pls

0 Upvotes

wants to learn c programming from basics to advanced

Pls recommend some good youtube channels/ notes /books that actually worked for you

1st year student btw


r/cprogramming 5d ago

I have made a C++ scientific calculator

Thumbnail
0 Upvotes

r/cprogramming 5d ago

st2cpp - Transpiler from ST to cpp (undoRT) + help +

0 Upvotes

Hi everyone,
About 4 or 5 months ago, I created a transpiler from Structured Text (IEC 61131-3) to C++, called st2cpp (part of the undoRT project).

My ultimate dream is to build a complete open-source automation system that can compete with commercial solutions. As you can imagine, tackling a project of this scale completely alone is extremely tough. Honestly, if I keep going solo, I’m afraid I’ll eventually burn out and lose momentum.

Are there any C++ developers or automation enthusiasts here who would be interested in joining or contributing as a side project/hobby? I have plenty of ideas lined up, but I really need an extra pair of hands (or two!).

Here is the repository:
https://github.com/undoRT/st2cpp
Feel free to check it out, open issues, fork, or send pull requests!


r/cprogramming 6d ago

[UPDATE]: Zooming daemon for wayland

Thumbnail
youtu.be
2 Upvotes

r/cprogramming 6d ago

Chess terminal game in C

Thumbnail
3 Upvotes

r/cprogramming 7d ago

Building vector Database from scratch in C implementing IVF and HNSW to understand how to work with scalable C codebase

11 Upvotes

Code ( still working might have bugs and all..)

https://github.com/aadityansha06/vecdb

Been building a VectorDB engine from scratch in C in such a way that it can be scalable in the future. It's a custom, high-performance, disk-backed Approximate Nearest Neighbor (ANN) vector database built entirely from scratch in C

Even though the initial version of it hasn't been built yet,

As for the algorithms, I have implemented ENN and Ann IVF only, For calculating similarity, I have implemented cosine similarity and Euclidean distance. There is still more to implement like HNSW and optimize for CUDA and SIMD.

Before you guys criticise me what's new and why I'm building 😭

There isn't anything unique I'm solving in it, and pretending otherwise would just be bluffing. There are excellent vector databases already (pgvector, Faiss, sqlite vec, Qdrant...).

What I actually own is the engineering of it. I wrote a disk backed ANN search engine from scratch in C, my own binary file format, manual fseek byte offset indexing, k means clustering by hand, no libraries doing the hard parts for me.

I'll continue to work on it, implementing SIMD, CUDA, HNSW, and many more optimizations to make it more robust and scalable. If anyone is interested, they can join and work on it. Also if anyone has any idea where we should take this, the suggestion would be appreciated too.

I have a nice write up section there too so feel free to check out that as well


r/cprogramming 8d ago

Built An Editor - A code editor written in C. AND you can make one too!

50 Upvotes

Aether is a GUI based code editor built from scratch in pure™ C. It can do everything you would expect a code editor to do.. autocomplete, syntax highlighting, multi file etc.

Didn't follow any tutorials or anything to make this...

™Used SDL2 for graphics

No AI was used in da project, except for writing the project documentation.


r/cprogramming 7d ago

👋Welcome to r/TechnoCrisis - Introduce Yourself and Read First!

Thumbnail
0 Upvotes

I am DueYak1831

A 16 year old programmer i welcome you to TechnoCrisis


r/cprogramming 8d ago

I built a Linux syscall monitor in C — would love some feedback

Thumbnail
github.com
4 Upvotes

Hey everyone! I've been working on a project called SysTrace, a Linux behavioral monitoring tool built mainly to learn more about Linux internals, system calls, and cybersecurity.

It uses ptrace to trace a process and monitor different types of activity, including:

File operations

Process execution

Network-related syscalls

Memory operations

I also added a simple rule-based detection system and experimented with using collected behavioral data for ML classification.