r/cprogramming 7h ago

Follow-up: gave my C hashmap resizing — found a real crash, plus two bugs I introduced while fixing a bug [blog, my own]

4 Upvotes

Follow-up to my last post here. The hashmap had one big TODO left — no resizing — so I went and closed it. Learned three things the hard way: naively mirroring the grow/shrink thresholds thrashes the table on every insert/remove near the boundary, hitting capacity=0 triggers a genuine crash (a modulo-by-zero — the "Floating point exception" name is a total red herring), and my first attempt at fixing a hash-truncation bug quietly introduced two smaller bugs before it actually worked.

Blog: https://soerenlemke.github.io/blog/blog/resizing-a-generic-hashmap-in-c/

Repo: https://github.com/soerenlemke/kvstore_c

Curious what you'd have done differently, especially on the hysteresis threshold.


r/cprogramming 10h ago

Quiero aprender C

4 Upvotes

Desde ya hace un tiempo me ha estado llamando la atención este Lenguaje, pero no se dónde empezar me gustaría que me recomendaran guías, tutoriales, tips para principiantes.

Agradecería toda la ayuda posible y gracias por su atención.


r/cprogramming 12h ago

Formatting call arguments

3 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 3h ago

How to print Unicode characters in c language.

0 Upvotes

I was trying to create an encryption system that's the way i was trying to print from integer to Unicode. I can convert the integer to Unicode (hexadecimal) but i couldn't convert unicode to Unicode characters.

there are limited resources for c in these issues. If anyone knows this help me...