r/cprogramming 6h ago

Pivot from React/.NET to C++ Systems / HPC vs Platform Engineering? Need advice from guys in the field.

Thumbnail
0 Upvotes

r/cprogramming 14h ago

Trying to make a tool that prints stuff between a certain range

0 Upvotes

the code from what ik works from what i know and from tests i have done.i want to know how can i optimize it more because i suspect that there can be certain parts of it which i don't even need maybe. so can you guys look at my code and tell me what i can improve upon??

here is the repo

thanks in advance


r/cprogramming 12h ago

A C subset that compiles faster than Tiny C Compiler - Cm1 (C minus 1 or C - 1) programming language

0 Upvotes

Hi everyone,

I'm working on a programming language that compiles a subset of C. It is called Cm1 (meaning C minus 1) and you can writing and running C codes directly on your browser at https://cp1-lang.org/cm1/editor.html in a fraction of a second.

Why is it faster to compile than Tiny C Compiler? It is because Tiny C Compiler is a true compiler creating native binaries whereas Cm1 is a bytecode interpreter allowing you to test, debug, edit code and recompile very quickly or even do hot reloading. Cm1 can be used as a scripting language for shell scripts and video games, but this just a small use case because in theory, you can run 90% of your ENTIRE video game or software C program through Cm1's bytecode interpreter and leave 10% to compiled C and reap the benefits of very fast compilation and hot reloading.

100% Cm1 codes are compilable by GCC and Clang but the reverse is not true since Cm1 is just a subset of C. Major features that are omitted are function pointers, structs/unions inside functions, nested structs/unions. This programming language is under heavy development and I want to know if this comes as interesting to some of you. I'll try to post again on this subreddit if I got to bind Raylib game library to Cm1, allowing people to write Raylib games directly on their browser (works offline).

I know that programs that are written in C compiles fast already and there's even an existing compiler that is very fast (Tiny C Compiler). However, I'm the developer of Cp1 programming language (cp1-lang.org), which is a language that "transpiles" to C, and I aim to upgrade Cp1 by targeting the Cm1 language then compile it to bytecode in one command instead of a separate step in Makefiles or build scripts. This will make Cp1 very fast to compile for debug builds.


r/cprogramming 1d ago

Can someone tell me about pointers in linked lists?

8 Upvotes

Hi guys, I’m currently learning about data structures in C and have reached the topic of linked lists. I’ve run into a question regarding the functions used to manipulate them—specifically, while I clearly understand expressions like `p->next` and `p->data`, I’m confused about assignments like `p = newnode` and `p = p->next` (where there is no `->` operator on the right side). When I asked an AI, it simply told me that `p` is "just a pointer variable," but I don't quite grasp that explanation. Why do we treat a linked list element (or variable name) as a pointer variable in this way? Could an expert please explain the meaning behind this? and this is my code.

bool Insert(node *L, int data)
{
    node *p = L;
    while (p->next != NULL)
        p = p->next;


    node *newnode = (node *)malloc(sizeof(node));
    newnode->data = data;
    newnode->next = NULL;
    p->next = newnode;


    return true;
}

r/cprogramming 1d ago

Myshell

Thumbnail
github.com
4 Upvotes

Basic project to learn more about Linux system calls and C programming. I accept any criticism.


r/cprogramming 1d ago

Guys so I am in my college rn and want to learn c as it is in my course

0 Upvotes

As in title, I was wondering are there any good sites/channels for me as I am beginner and want to get good help from it as it is gonna help me alot for the next four years


r/cprogramming 2d ago

C++ question

Thumbnail
0 Upvotes

r/cprogramming 3d ago

YAM Now Supports the C Language Spoiler

Thumbnail
3 Upvotes

r/cprogramming 3d ago

Commutative Complex Number Theory in Plain C

Thumbnail
leetarxiv.substack.com
5 Upvotes

r/cprogramming 3d ago

looking for discord server to practice by teaching

Thumbnail
0 Upvotes

r/cprogramming 4d ago

VMS: A custom Fantasy 32bit Computer with a custom Hardware

Thumbnail
github.com
3 Upvotes

About a year ago, I started building a custom computer architecture in C as a learning project (I know it seems like a lot considering the code I wrote, but I rewrote the entire compiler at least five times, starting from a C-like language and ending up with a very simple custom language). I designed the instruction set, wrote an emulator, and implemented a custom high-level assembly language called BSL (Base System Language). The code is very messy because I make a lot of changes while writing it and often forget things that shouldn't be there. So I'd really appreciate feedback on the architecture and code quality. (I'm 15 years old and Italian, sorry for my English). Edit: I changed the project name from VMS to SPRK32.


r/cprogramming 4d ago

Bulletproofing User Sync: Handling Clerk and Auth0 Webhook Failures

0 Upvotes

If you're building a web application today, chances are you aren't writing your own authentication system. Managed identity providers like Clerk, Auth0, and Kinde have become the default choice, offering out-of-the-box support for passkeys, multi-factor authentication, and enterprise SSO. That convenience introduces a distributed-systems problem, though: data synchronization. When a user creates an account on a managed auth provider, that system has to notify your primary application database so you can create a matching user record. Please read the complete article here - https://instawebhook.com/blog/bulletproofing-user-sync-handling-clerk-and-auth0-webhook-failures

This happens through webhooks. But what happens if your server is down, your serverless function cold-starts and times out, or your database is momentarily locked when that webhook arrives? A user successfully signs up with your auth provider, but your application has no idea they exist. That breaks the very first login experience, and it's how phantom accounts, broken onboarding flows, and frustrated users happen.

This guide walks through the anatomy of webhook-driven auth architecture, current Auth0 and Clerk webhook practices, and how a resilience layer — using InstaWebhook as a worked example — closes the gap that idempotency and signature verification alone can't.


r/cprogramming 4d ago

Lifetime safety and invalidation without a borrow-checker: using type system analysis to get rid of many potentially invalidation cases WITHOUT annotations.

Thumbnail open-std.org
1 Upvotes

r/cprogramming 4d ago

Can anyone explain exactly why I got these random values for a C simple program?

Thumbnail
0 Upvotes

r/cprogramming 5d ago

Wrote a tiny version of argp for CLI parsing in embedded environments

Thumbnail
github.com
4 Upvotes

r/cprogramming 6d ago

Help understanding warnings/errors when dereferencing void pointers

5 Upvotes

SOLVED

I am very new to C and playing around with void pointers. I have a structure which will store a value, however the type of that value depends on other things so I have chosen to use a void pointer. When attempting to dereference this void pointer I either get the correct output but with a warning, or I get a segmentation fault, depending on how I go about it. I have included a simplified version of the issue here:

```C

include <stdio.h>

int main()

{

// Simplification of the defective code

struct myStruct

{

    void * voidPtr;

};

struct myStruct s1;

s1.voidPtr = (int *) 123;



\*

This works but gives the warning:

format '%d' expects argument of type 'int', but. argument 2 has type 'int \*' \[-Wformat=\]i

*/

printf("%d\n", (int *) s1.voidPtr);



// This causes a segmentation fault

printf("%d\n", *(int *) s1.voidPtr);



return 0;

}

```

Any help understanding why it behaves this way would be greatly appreciated.

Solution

I thought the line

C s1.voidPtr = (int *) 123;

Was assigning 123 as the value at the location of s1.voidPtr. However it has been pointed out that I was telling the pointer to point at address 123. What I needed to do was:

C int x = 123; s1.voidPtr = &x;

Thanks everyone who commented c:


r/cprogramming 6d ago

C programming confusion

0 Upvotes

🚨 I think something is wrong with me... 😅
Is it just me, or has C programming started feeling... easy? 👀
Pointers? 😴
Memory management? ☕
Segmentation faults? "Let's see where I messed up." 😂
I used to think C was the language everyone feared.
Now my biggest bugs are usually my own logic not the language itself. 🤦‍♂️
Seriously though...
Am I the only one who has reached the point where writing C feels as natural as writing Python?
Or is this just a dangerous level of confidence before C reminds me who's in charge? 😅
Please tell me I'm not the only one...


r/cprogramming 7d ago

What is the best way to learn Embedded C?

13 Upvotes

I've started learning embedded systems. Most important part of the journey is learning C programming. I'm confused as embedded C is a bit different than standard C. Can anybody guide me the best way to learn.


r/cprogramming 7d ago

Am I writing my parser wrong?

3 Upvotes

Simple question. I can't give exact code examples, but I have a string_t struct with methods like:

string_t split(string_t *string, string_t *on)

string_t split_sp(string_t *string)

string_t split_crlf(string_t *string)

char *s_strstr(string_t *needle, string_t *haystack)

void trim(string_t *str)

So on and so forth.

I've been using these so far to parse HTTP reqeusts, and I have come up against many minor problems:

"What happens if a header field appears with no value? I'll have to explicitly check for it."

"What happens if a sender puts a bunch of CRLFs in the middle? I'll probably need a check for that."

"Oh God, how will I handle unrecognized header fields? How do I recognize them?"

These, and other questions, have been leaving me pissed.

I recall reading through the LLVM projects Kaleidoscope language thing, where they create a parser for said language. Said parser doesn't use anything close to what I am, instead reading character by character without fuss.

Similarly, on my last post made here, the way comments were worded reminded me of that method, and how it probably works better.

I have written only a small part of the parser, so it isn't too late to tear down and rebuild. Simple question: should I? Are there benefits to swallowing the input token by token instead of taking the overarching view my string_t functions provide? Or vice versa?

It would help if I'd upload the code, I know, but I don't want to bother with that until the project is completed/near-completion.


r/cprogramming 8d ago

My real OS (D.eSystem 6.0.7 beta)

3 Upvotes

Hello everyone!!

D.eSystem 6.0.7 beta got a lot of polishing work. For example the versions 6.0.3 beta-6.0.6 veta were internial test versions,thats why 6.0.7 beta released.

D.eSystem 6.0.7 beta fixes major bugs in the calculator app and its the first D.eSystem which allows to change the wallpaper in the D.eShell.

D.eSystem 6.0.7 beta release on github: https://github.com/D-electronics-scratch/all_D.eSystem_versions/releases/tag/v.6.0.7_beta

Github main page: https://github.com/D-electronics-scratch/all_D.eSystem_versions


r/cprogramming 8d ago

Lightweight, zero-bloat UI libraries or strategies for a real-time C simulation?

Thumbnail
2 Upvotes

r/cprogramming 8d ago

Tensor is the might: a single-header tensor library in C

Thumbnail zserge.com
2 Upvotes

r/cprogramming 8d ago

I just wrote this program on Programiz Online Compiler.

Thumbnail
programiz.com
0 Upvotes

Pb


r/cprogramming 9d ago

Casino on c

3 Upvotes

Thanks to everyone . A special thanks to those who suggested the /dev/random - this very help for my tasks.


r/cprogramming 10d ago

From a video game to the UNIX kernel, the wildest origin story I've stumbled across (and why I'm learning C)

65 Upvotes

I just started learning C using C Programming: A Modern Approach, and out of pure curiosity I fell down a rabbit hole trying to figure out where the language actually came from. What I found reads like a movie plot, and somehow it's almost never mentioned in the courses that teach the language itself.

It starts in 1969, with Ken Thompson writing a little game called Space Travel, a spaceflight simulator, to run on a GE-635 mainframe at Bell Labs. Only problem: every play session was burning around $50 to $75 in machine time, and the experience still wasn't great. So Thompson went digging around the lab and found an old PDP-7 nobody was using anymore, sitting in a corner collecting dust. He and Dennis Ritchie decided to port the game over to it.

Here's the part that gets me: to make the game actually run on that machine, they first had to build a file system, a memory manager, and a command interpreter from scratch. In other words, UNIX exists because two guys wanted to play a game without going broke.

From there it snowballed. They wrote the B language, got a self-hosting compiler working, and eventually B evolved into C, with types, pointers, structs, the works, specifically so they could rewrite the UNIX kernel in something higher-level and never again have to write an entire OS in raw Assembly. All of that lived mostly in Thompson and Ritchie's heads for years, until it finally got written down in 1978 in the legendary K&R book, The C Programming Language.

There's something genuinely moving about realizing every #include <stdio.h> you type traces back to a dusty PDP-7 and a game that was too expensive to play.

If anyone's got more history like this, or book recommendations beyond K&R, I'd love to hear them. Happy coding, everyone.