r/cprogramming

What's the point of using local arrays if there is no guarantee that the stack won't be overflowed?

Basically title. I feel deterred from using local arrays because I cannot check in my C code if the allocation was successful.

Is it true that in C you cannot guarantee that a local array will not overflow the stack? Isn't it detrimental to any memory safety critical application. For a stack allocation, aren't there any guarantees in the C language that could help me make at least some decision about the safety of it?

If memory safety was critical, should local arrays be avoided for the possibility of stack overflow – and only dynamic allocation should be used?

Malloc gives you NULL when heap has not enough space but alloca and local arrays don't give any warning when stack has no space. Why does alloca have no similar system? I get that you can check the size and calculate the remaining space on the stack using system's api and that'd be a guarantee that the space won't be a problem.

reddit.com
u/Longjumping_Ad_8175 — 7 hours ago

anonymously initializing pointers in self-referential data-structures?

I have a recursive data-structure (a simple linked list for purposes of this example) and wanted to statically define a linked-list. The following works fine:

#include <stdio.h>
typedef struct mytype_tag {
    struct mytype_tag* next;
    char* data;
} mytype;

mytype a = {
    .next = NULL,
    .data = "a",
};
mytype b = {
    .next = &a,
    .data = "b",
};

int
main() {
    mytype* s = &b;
    int i = 0;
    while (s) {
        printf("%d: %s\n", i++, s->data);
        s = s->next;
    };
}

However, I have to explicitly define/declare a and then have b take &a.

Is there a way to do this with anonymous/unnamed intermediary structures, thinking an imaginary syntax something like

mytype b = {
    .next = &((mytype)={
        .next = NULL,
        .data = "a",
        }),
    .data = "b",
};

so I can build up the linked-list without naming each intermediary instance?

reddit.com
u/gumnos — 11 hours ago

I can't seem to grasp the fundamentals right

I just finished the C programming course from BroCode on YouTube, and I'm still finding it hard to write a simple to-do list, is this a skill issue thing or it's just normal, I feel kinda incompetent

please could I get tips to help master the language properly!

reddit.com
u/Hot_Huckleberry43 — 17 hours ago
▲ 46 r/cprogramming+4 crossposts

hobby 32-bit x86 operating system called **nyanOSv1 **

Hey guys,

For the past few months, I've been working on a hobby 32-bit x86 operating system called **nyanOS **. I wanted to move away from text mode as fast as possible, so I ended up programming the VGA registers directly (Mode 13h, 320x200x256 colors) to build a custom graphical user interface without relying on any BIOS calls after boot.

It's written in C and Assembly, booting via Multiboot.

### What's working right now:

* **Interrupts & Drivers:** Real IRQs for the PS/2 keyboard (IRQ1), mouse (IRQ12), and PIT timer (IRQ0). No busy loops for polling.

* **Window Manager:** Draggable, focusable, and z-ordered windows, complete with a taskbar and a start menu.

* **RAM File System:** A basic in-memory FS that handles real read, write, list, and delete operations.

* **Built-in Apps:** A working terminal shell, a text editor (Notepad with save/load), a basic mouse-driven paint program, and a local document viewer (packaged as a "browser" that reads a tiny custom markup from the RAM FS).

The source code is heavily commented, especially around the tricky parts like the GDT, IDT remapping, and direct VGA port I/O, because I wanted it to be readable.

* **GitHub:** https://github.com/yunusemreduran388-ux/NyanOS-v1

* **mywebsite** https://yunusemreduran388-ux.github.io/

* **Releases:** I also uploaded the pre-compiled `.iso` and `.elf` files to the GitHub Releases tab, so you can just grab the ISO and test it instantly in QEMU via `qemu-system-i386 -cdrom nyanos.iso` without needing to build it from source.

u/PickleFeatherRs — 3 days ago
▲ 47 r/cprogramming+5 crossposts

YCETL: a compile time STL like template library to generate data structures that can be used at runtimes

I posted this days ago but the 'automated admins took it down saying was generated by AI' as the formulation was maybe too academic. Trying now with other words.
Short storry: I wanted to generated python glue code for webgpu based on webgpu header. After exploring libclang and generating correct results, I wanted something more generic, more 'built in into C++'. At the beginning I thought will be easy with constexpr compile time tricks, but turned out the compile time 'runtime' is very restrictive. And I solved the challenges with ycetl. https://github.com/zokrezyl/ycetl

This is not a toy project, it is work of couple of months, fight with windmills of compile time runtime. If you see issues that can make it production ready, please share.

u/Ok_Path_4731 — 3 days ago

C-minus-minus

https://github.com/DASKR515/C-minus-minus
C-- (Cmm) Language Reference is a community-driven documentation project dedicated to C-- (Cmm), the native intermediate representation (IR) used internally by the Glasgow Haskell Compiler (GHC).

The goal of this repository is to provide a centralized reference covering the language syntax, compiler usage, practical examples, memory layout, control flow, foreign function interfaces (FFI), and interoperability with native C libraries.

This project is not a compiler, framework, runtime environment, or replacement for GHC. Instead, it serves as a complete reference for developers interested in learning, understanding, and writing Cmm programs.

u/Own-Psychology-732 — 3 days ago

Personal Finance/Balance program: Encryption

I'm working on a program for tracking my account balances, budgeting/saving, spending analysis, etc. The program won't use/store sensitive info like SSN, account numbers, etc. - just transaction amounts, transaction categories/descriptions, and made-up account names. Additionally, there will be no web transfer - it's all offline, manual entry.

My question is: Do I need to worry about encryption?

Sorry if this sounds ridiculous - I just don't want to inadvertently screw myself with a hobby project.

reddit.com
u/serfizzler — 3 days ago
▲ 10 r/cprogramming+1 crossposts

procsnap – a minimal Linux process profiler in C (no dependencies, suckless philosophy)

I wrote a small CLI tool that snapshots /proc info for a given process — name, state, PPID, memory usage, cmdline. It also supports JSON output, process search by name, and a diff mode to compare a process state over time.

No external dependencies. Single binary. ~600 LOC.

procsnap <pid> / procsnap --json <pid> / procsnap --diff <pid> / procsnap -g <name>

Source: github.com/DankDown10256/procsnap

Feedback welcome — especially if you find edge cases or have ideas for v1.1 or to help me create a doc.

u/Humble-Insurance-768 — 4 days ago
▲ 25 r/cprogramming+4 crossposts

A Multi-Dimensional, Per-Pass Empirical Study of the LLVM Optimization Pipeline

Hi Folks!

I simply want to share this empirical study on the LLVM -O3 pipeline on the PolyBench suite.
I don't want to bore you with too many details that are already in the paper.
Any feedback is welcome :D

Blog post: https://federicobruzzone.github.io/posts/a-multi-dimensional-per-pass-empirical-study-of-the-llvm-optimization-pipeline.html
arXiv: https://arxiv.org/pdf/2606.31238

reddit.com
u/FedericoBruzzone — 5 days ago
▲ 0 r/cprogramming+1 crossposts

will my marks be cut for writing #include<stdio.h> instead of #include <stdio.h> in my c programming exam

just gave my second semester exam and i have been writing #include<stdio.h> instead of the genral one technically my syntax is correct but i am scared that what if what if examiner does't have knowledge that my syntax is correct as well and reduces my marks or fails me :((((((((((((((((((((((((((((((((((((((((((((((((((((

i am reallly scared since i come from pretty trashy university and i just i hope i don't get less marks than expected or fail the subject

can any senior give me any advice in the comment or dms please?

reddit.com
u/Existing-Water-1905 — 5 days ago

How would you learn compiler development from scratch if your goal was to build a real compiler?

I have become extremely fascinated with compiler development and want to eventually build a real compiler as a hobby project. My goal isn't just to follow a tutorial and copy code—I want to understand how compilers work at a deep level.

I've already started learning the prerequisites (computer organization, C++, data structures, etc.), but I'm looking for advice from people who have actually built compilers.

Some questions I have:

  • If you had to start over today, what learning path would you follow?
  • Which books would you consider essential?
  • Are there any projects or milestones that helped everything "click"?
  • Should I implement multiple small compilers before attempting a serious one?
  • Is it better to use tools like Flex/Bison at first, or hand-write the lexer and parser to understand the fundamentals?
  • How much compiler theory should I learn before I start building?

I'm looking for recommendations on books, papers, courses, blogs, repositories, or any other resources that helped you become proficient in compiler engineering.

I'd also appreciate hearing about mistakes you made while learning that you'd avoid if you were starting again.

Thank you, and yes this is all ai generated , I am sorry for this my English very bad i have to use ai

reddit.com
u/Ok-Assistance-2480 — 4 days ago

Untyped structs in C; yay or nay?

In C++, when you want to make a struct or class or function that acts upon/uses a type whose features are generally unimportant, you use templates. For example std::vector&lt;T&gt;, and that (as far as I'm aware), tells the compiler that whenever it sees something like std::vector&lt;AStruct&gt;, it should generate code that acts on a vector of AStructs. This is a useful feature that C doesn't have (which I'm fine with, there are workarounds, especially a really fucky workaround I saw on SO).

I'm assuming that one advantage of C++'s templates is that it can use SIMD, vectorized instructions, and all the other fun stuff that make a lot of actions faster, because it knows the size of std::vector&lt;int&gt; vs std::vector&lt;string&gt;.

In C, when I try to make type that's generic (especially a data structure like a priority queue), I have to have a (usually) void * and a size_t, one for where the data is, and for how big one object of that data is.

Here comes my question:

Can most C compilers, based off of the usage of the structs, realize that "Oh, this is basically always guaranteed to be used on the type int32_t, so I can just compile it with that in mind", or do I have to un-Genericify my struct for that?

(Note: I am aware of using Macros to achieve technically-generic-but-typed structs, however there are apparently issues with "eating your own dog food" when you try to make a queue of queues, for example. I'd rather avoid that, even if I probably won't eat my own dog food)

reddit.com
u/SheikHunt — 6 days ago

Please, can all of you give me idea on good resources on system level development ?

I want to study system level development with C and automation with python/bash.

So, after thinking so much I want some resources. Mainly on C including //Best resource to learn to make a shell//

I am thing of learning cpp, when I will be ready to see death eye to eye.

Now, I can't figure out what to study. I am a busy scheduled high school student so I will have very less of time.

I have done python 2 years ago, and C 6 months ago. And, used linux with bash commands.

reddit.com
u/Rayman_666 — 6 days ago
▲ 0 r/cprogramming+1 crossposts

Beginner question

Is it safe to say that figures, at the core are technically constant variables in C?

I am still very far in the journey learning about lvalues and rvalues so I am genuinely curious.

reddit.com
u/Soft-Cauliflower-670 — 6 days ago
▲ 14 r/cprogramming+1 crossposts

tmuzika 1.1.3 released — stability improvements, faster playlist loading, bug fixes

Quick update: I just released tmuzika 1.1.3.

This is a small maintenance + usability update based on recent fixes and feedback.

What’s new:

improved stability in playback handling

fixed a few edge-case crashes in file navigation

better performance when loading large playlists

minor UI polish and consistency fixes

This release is mainly focused on making the app more reliable and smoother in daily use rather than adding major new features.

As always, feedback is welcome — it directly shapes these updates.

github.com
u/Turbulent_Forever764 — 7 days ago