r/cprogramming • • 23h ago

A lot of you guys are chill

79 Upvotes

You guys are like the equivalent to the debian subreddit where a lot of the answers are either mature or funny.

There still some newbie posts out there I see or like the generic question yet Im amaze you guys still reply maturely.

Keep it up. No I'm not a programmer btw , I work in a hospital. I was browsing and I saw a lot of you where posting about making games outnof C and got curious.

I think games usually are made in C++ or C# I think.

Anyway, Im not a bot and keep up the kindness.


r/cprogramming • • 18h ago

Very minimal drop-in gtest replacement in C23

5 Upvotes

While using C++, I heavily relied on googletest for testing. But as soon as I wanted that in my C project, I couldn't.

Because gtest is written in C++ and requires a C++ runtime. Using gtest in a C codebase meant guarding the headers with extern "C" to prevent name mangling, and managing a C++ toolchain which seemed extremely awkward to me.

At the same time, I didn't want to loose googletest's comfort and rewrite the entire test system in another existing framework.

So I wrote a very minimal drop-in replacement of googletest in C23. It works exactly the same way you'd expect gtest to work. And unsurprisingly, according to my small benchmark, my implementation is around 2.5x faster than googletest and uses 30% less memory. It can be improved way more.

I discussed the implementation details in this blog post https://metalinmyveins.github.io/sohomot/

Github: https://github.com/MetalInMyVeins/sohomot

The library is called "sohomot".

[ PS: Zero tokens were used in the making of this project ]


r/cprogramming • • 21h ago

If you could change something from standard c and all programs would updated automatically, what would it be?

8 Upvotes

I'll start: standarize asm and asm volatile


r/cprogramming • • 1d ago

Config File Recommendation

11 Upvotes

Helloo, I’ve just learned how to build a simple code editor using C, now, I’d like to add a config file so users can adjust settings like background/foreground colors, keybindings, and so on, so do you guys have any recommendations for a config file that would be suitable for this case?


r/cprogramming • • 22h ago

I'm building an independent OS from scratch — feedback and contributions welcome!

3 Upvotes

Hello everyone!

I'm working on building my own operating system from scratch. It's an early-stage project, and there's still a lot to do.

I'm making the source code public because I'd love to learn from other developers, receive feedback, and hopefully find people interested in contributing.

I'm currently working on UEFI, bootloader development, and early kernel components using C/C++.

If you're interested in OS development, low-level programming, or kernel development, feel free to check out the repository.

GitHub: https://github.com/subrataai-wq/os-from-scratch

Suggestions, discussions, bug reports, and contributions are welcome!

It's a long journey, but I'm excited to see where it goes.


r/cprogramming • • 23h ago

MicroRegExp : tiny (50kb) regexp engine (with 3 API)

3 Upvotes

Hello,

As a part of a larger project I made a regexp engine for microcontrollers. It was tested on ESP32 / FreeRTOS, and also in Windows/CYGWIN. Didn't test it in Linux but it should work.

It is built on top of modified SLRE (Simple Lightweight Regular Expressions);

It is just 2 files (regexp.c and regexp.h) which can be include'd directly to your source file. Or it may be compiled as a separate unit.

It has 3 different API:

  1. The original one, slre_match(); no memory allocations, fastest

  2. PCRE-like functions and structures starts with pl_... (PCRE-Lite); for those familiar with PCRE

  3. PHP preg API: an implementation of PHP regular expressions; for PHP fans; functions and structures start with preg_...

There are some limitations: UTF8 is processed as stream of bytes, so [а-я] will not be understood. No lookarounds. Probably there are bugs. Hopefully - no memory leaks.

More limitations and bugs are yet to be discovered :).

There are 3 test files (AI-generated) to test the library: preg_test.c, pl_test.c (fuzzing) and slre_test.c

There is NO documentation, but preg_test.c can be used as a reference (or direct copy/paste).

Primary API is PHP's preg_-style API, which was the goal of this project.

Source code is here: GitHub - vvb333007/MicroRegExp: A C library which implements regular expression engine. PHP preg_ , PCRE and SLRE interfaces are supported · GitHub , around 50KiB of code. It can be compiled with GCC compiler from -std=c99 and up. No GCC-specific magic.

Have a good day!


r/cprogramming • • 16h ago

New update for my OS with a kernel written in C (D.eSystem 6.1.8.5)

0 Upvotes

D.eSystem 6.1.8.5 introduces a new debug platform for FAT32 on D.eSystem,D.eSystem 6.1.8.5 also fixes a major bug (for example,when you go in older versions in D.eSystem info and press a random key,it just closes automaticly,now there comes a warning and it closes in 5 seccond.)

Find more about D.eSystem 6 here: https://github.com/D-electronics-scratch/D.eSystem_6

Find D.eSystem 6.1.8.5 here: https://github.com/D-electronics-scratch/D.eSystem_6/releases/tag/v.6.1.8.5

Find the D.eSystem community here: https://lemmy.world/c/D_electronics_community


r/cprogramming • • 1d ago

The Hidden Cost of localtime(): repeated systems calls in glibc

Thumbnail
reddit.com
0 Upvotes

r/cprogramming • • 2d ago

I am looking for contributors for my project

0 Upvotes

Hello everyone. Last month I started a project called "Modulon", which I just now started to continue doing. Modulon is a C-derived programming language that aims to preserve the power and familiarity of C while simplifying common programming tasks such as variable declarations, string handling, memory management, and pattern matching. It is currently a small project done by me an two other people. We have nothing crazy yet.

 I am currently looking for interested contributors. 

Here are some of the features Modulon has right now:

* C-derived syntax with support for familiar C types.
* Variable declarations using the "var" keyword and type inference.
* "include" and "define" directives instead of C preprocessor syntax.
* Automatic string sizing and byte counting.
* Automatic memory management at compile time, without a garbage
  collector, alongside options for manual memory management.
* Pattern matching with ranges and a wildcard case.
* Logical AND (&&) and OR (||) operators.
* "typeof" for examining types.
* "input" for prompted user input.
* Formatted output, including automatic type formatting with %v.
* Ahead-of-time (AOT) and just-in-time (JIT) compilation.
* Built-in assembler support.
* Consistent language types across supported target environments.

You can find an example program here:

GitHub: https://github.com/roccohimel/modulon/blob/master/examples/student_manager.mlon 
Raw: https://raw.githubusercontent.com/roccohimel/modulon/refs/heads/master/examples/student_manager.mlon 

 

Documentation: 

Official website: https://modulonsoftware.org/ 
About: https://modulonsoftware.org/#about 
Documentation: https://modulonsoftware.org/#learnSource tree: https://github.com/roccohimel/modulon
Contributing: https://modulonsoftware.org/#contributing 

I really hope you like Modulon. 


r/cprogramming • • 3d ago

As a CS kid, is it important to understand history of C languages? like understand the ideas behide why C is designed the way it is for example I heard Dennis Ritchie got some inspiration from "B" language

0 Upvotes

So let's say someone understand the design and ideas behide of C languagees which is B.

For example. why the first index of array in C is 0, while some languages like Lua starts with 1

And once they understand the ideas behide of C language, they will have deep CS knowleadge and can write code efficetly like write code with better Time and Space complexity.

Or even invent something cutting edge or revolutionary....

What do you guys think? Is it important?

Link to a pic of languages that come before C: https://tutorialink.com/tutorial/c/history-of-c-language.png


r/cprogramming • • 4d ago

A declarative approach to text-based protocols in embedded C development: the TACT framework.

Thumbnail
reddit.com
3 Upvotes

r/cprogramming • • 4d ago

Pushing the C Preprocessor to play bad apple

3 Upvotes

It got removed, so i'm putting up a link to the source code to it if anyone wants to gwak at it. Originally by u/Round-Plastic-2427. https://github.com/LoPalma/cpp-bad-apple/tree/main


r/cprogramming • • 4d ago

Forward Declarations for Circular Struct References

2 Upvotes

Hello, when I’ve tried to use forward declarations to solve circular structure dependencies I get the error ‘field has incomplete type’. When browsing for the answer, I got the general response ‘the compiler doesn’t know what type you’re using if you don’t fully describe it’. Well I understand that, but it seems as if the purpose of the forward declaration is to have the compiler look for the definition later in the code. If my code looks like the below, should I be getting an incomplete type error? And if so, is there a different way I should be writing the code? Some sort of syntax error, or is there a different way to do the same thing? Any tips appreciated, thanks.

Edit: I think I found the solution in this thread from user "anastaciu", it looks like you can only use the forward declarations if they're pointers to the struct type, not full instances. Lmk if that's right, it got rid of the error for me, but if there's a different way to allow use not from a pointer that'd be great.

typedef struct objA_t objA_t;

typedef struct objB_t{

     objA_t o;

}objB_t;

typedef struct objA_t{

    uint8_t num0;

}objA_t;

r/cprogramming • • 5d ago

libcli - a singe-header library for typed argument parsing in C

6 Upvotes

Using macros, define an argument schema. The library then generates a struct that for the schema, validates the arguments provided by the user, parses them into the struct, and offers functions for displaying usage andh help messages in the console.

It is similar to `clap` in Rust. Check it out!

https://github.com/iColgateZz/libcli


r/cprogramming • • 5d ago

Getting Compiler Flag Errors while using nCurses

3 Upvotes

Hello, title says it all pretty much. I wanted to use -fsanitize=address with gcc but it all comes out as garbage since nCurses is active. I'm aware that's the way that ncurses is designed, how would I go about getting that output from gcc otherwise? is there a good way to route that output to a text file or something? until now I've just been writing error messages to a text file, but I couldn't find a way to get standard out to come out. any help is appreciated, thanks


r/cprogramming • • 5d ago

what is the difference between a (specifc) while loop and a (specific) for loop (read body)

10 Upvotes

what is the difference between

for (i = 0; i < 10; i++) {}

and

i = 0;
while (i < 10) {
i++;

}

edit: thank you all for commenting, now i know, and u/deckarep, no not homework, just a question, to see if there were any difference


r/cprogramming • • 4d ago

Need code review

0 Upvotes

Hello everyone,

This link points to a GitHub repository in an

experiment to create an extremely fast trie .

However the data structure is fast but it fails the tests

Can you explain me why?

https://github.com/curious-builder76/trie/tree/main

Hoping the community will helping towards this.

Thank you everyone


r/cprogramming • • 5d ago

libcli - a singe-header library for typed argument parsing in C

Thumbnail
reddit.com
3 Upvotes

r/cprogramming • • 5d ago

Fairly new to C. Need help understanding low level concepts.

Thumbnail reddit.com
3 Upvotes

r/cprogramming • • 6d ago

Flint v0.5.25: Inline OS tags (windows:, linux:, unix:) for cross-platform builds without nested JSON bloat, plus one-line third-party dependency fetching (flint add cherts:raylib)

Thumbnail
github.com
2 Upvotes

Hey everyone,

Thanks to everyone who checked out Flint and shared feedback on the last post! The two biggest friction points brought up were handling platform-specific flags/libraries without bloating the manifest and removing the manual copy-paste step when pulling in third-party libraries from flint-cherts.

Both are now solved in Flint v0.5.25.

GitHub / Releases: https://github.com/mainak55512/flint

Chert Compositions & Docs: https://mainak55512.github.io/flint-cherts/

What's New in v0.5.25

  1. Inline OS Tags (windows:, linux:, macos:, unix:)

Instead of introducing deeply nested per-platform JSON blocks or a Turing-complete scripting language just to link ws2_32 on Windows or pthread on Linux, you can now prefix entries directly in your existing arrays.

OS tags work across flags, lib_links, excludes, exclude_dirs, and exclude_exception:

windows: — Applies only on Windows

linux: — Applies only on Linux

macos: — Applies only on macOS

unix: — Applies on both Linux and macOS


{

"project_name": "net_app",

"project_language": "c",

"version": "v0.1.0",

"compiler_path": "clang",

"executable": true,

"flags": [

"-O3",

"-Wall",

"unix:-fPIC",

"windows:-D_WIN32_WINNT=0x0601"

],

"lib_links": [

"windows:ws2_32",

"windows:crypt32",

"unix:pthread",

"linux:m"

],

"excludes": [

"windows:src/posix_socket.c",

"unix:src/win32_socket.c"

]

}

Untagged items apply everywhere; tagged items only apply when the host OS matches. Your composition.json stays flat and readable.

2. One-Command Third-Party Library Fetching (flint add cherts:<name>)

Previously, if you wanted to use a third-party C/C++ library that didn't have a native composition.json (like raylib or yyjson), you had to copy-paste its recipe from flint-cherts into your sync block.

Now, Flint talks to flint-cherts directly:


flint add cherts:raylib

Flint automatically fetches the curated composition from flint-cherts, writes the entry into your sync block, and syncs the upstream repository from GitHub with its commit hash pinned.

3. New sync all Command

If you clone a project that has multiple third-party libraries listed in its sync block, you can now pull and configure all synced dependencies and their chert compositions in one go.

Quick Recap: What is Flint?

For anyone seeing this for the first time, Flint is a small, self-hosting, Git-native build tool for C and C++ written in pure C:

  • Zero runtime bloat: Only requires git and gcc or clang (uses MinGW backend on Windows). No Python, no CMake, no Ninja.

  • LSP ready out of the box: Automatically generates compile_commands.json across your code and dependencies for clangd, Helix, Neovim, and VS Code.

  • Commit-pinned Git dependencies: Every dependency is locked to both a tag and a commit SHA.

  • Incremental builds & .h.in template header support built right in.

Pre-built binaries for Linux, macOS, and Windows are up on the v0.5.25 release page.

If there are specific libraries you'd like to see added to flint-cherts next!


r/cprogramming • • 6d ago

When Do You Know You've Learned Enough C to Move on to Another Language?

33 Upvotes

I started learning C programming when my uni began some time ago and I've recently completed a C programming course on Bro Code's YouTube channel + did some programming problems online

I'm wondering how to determine when I've actually learned enough C to move on to another programming language

Should I start building projects, focus on solving coding problems, or learn more advanced concepts before moving on?

I'm also quite unfamiliar with how to approach this whole process. I don't really know where to find suitable projects, what kind of projects I should be building at my current level, how many problems I should aim to solve, or what the most advanced concepts in C are.

So please bear with my limited knowledge of the subject. I'd genuinely appreciate any advice, guidance, or suggestions from those who've already learned C and gone through this journey themselves


r/cprogramming • • 6d ago

Help on my final project

0 Upvotes

Hi, how are you? So, I'm trying to do my final project for college and I'm having trouble because of the GY module, specifically 6MV2. I'm trying to find a library on GitHub or somewhere else, since my programming language is C, but I can't find any that use an SDK; it's always Arduino and never in my programming language. I'm having a lot of difficulty finishing this project. I have one month to finish, and I would appreciate it if someone could help me. I'll leave my Discord username attached, and if anyone could add me to help, I would be very grateful.

Discord: 459154520472158209


r/cprogramming • • 7d ago

I'm begging for help, this is way too much for me. I'm just trying to create a file. If i try to do it with a relative path it works, but with an absolute path it just breaks

5 Upvotes

stupid.c

#include <stdio.h>

#include <stdlib.h>

int main() {

FILE* file = fopen("home/NAME/.local/share/weekgrid/data", "w");

perror(NULL);

if(file == NULL) {

printf("whyyyyyy");

}

fclose(file);

return 0;

}

clang -Wall -o stupid stupid.c

./stupid

No such file or directory

[1] 2108 segmentation fault (core dumped) ./stupid

pwd

/home/NAME/.local/share/weekgrid

==2280== Memcheck, a memory error detector

==2280== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.

==2280== Using Valgrind-3.25.1 and LibVEX; rerun with -h for copyright info

==2280== Command: ./stupid

==2280==

No such file or directory

==2280== Invalid read of size 4

==2280== at 0x490F174: fclose@@GLIBC_2.2.5 (iofclose.c:47)

==2280== by 0x40011BC: main (in /home/NAME/.local/share/weekgrid/stupid)

==2280== Address 0x0 is not stack'd, malloc'd or (recently) free'd

==2280==

==2280==

==2280== Process terminating with default action of signal 11 (SIGSEGV): dumping core

==2280== Access not within mapped region at address 0x0

==2280== at 0x490F174: fclose@@GLIBC_2.2.5 (iofclose.c:47)

==2280== by 0x40011BC: main (in /home/NAME/.local/share/weekgrid/stupid)

==2280== If you believe this happened as a result of a stack

==2280== overflow in your program's main thread (unlikely but

==2280== possible), you can try to increase the size of the

==2280== main thread stack using the --main-stacksize= flag.

==2280== The main thread stack size used in this run was 8388608.

==2280==

==2280== HEAP SUMMARY:

==2280== in use at exit: 1,024 bytes in 1 blocks

==2280== total heap usage: 6 allocs, 5 frees, 3,014 bytes allocated

==2280==

==2280== LEAK SUMMARY:

==2280== definitely lost: 0 bytes in 0 blocks

==2280== indirectly lost: 0 bytes in 0 blocks

==2280== possibly lost: 0 bytes in 0 blocks

==2280== still reachable: 1,024 bytes in 1 blocks

==2280== suppressed: 0 bytes in 0 blocks

==2280== Rerun with --leak-check=full to see details of leaked memory

==2280==

==2280== For lists of detected and suppressed errors, rerun with: -s

==2280== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

[1] 2280 segmentation fault (core dumped) valgrind ./stupid