r/C_Programming 4d ago

Article I coded in C, and it (me) crashed my laptop

0 Upvotes

Now I have been coding C for a while, so I do know a lot of solutions to specific problems. But to be honest, most of the time I look back at my old code, copy paste, and then re-factor it depending on my current project. I used SHM for my cherries(.)works Pulse project. The reason for that was, Pulse ran on two separate processes; One was the daemon that ran the monitoring in the background, and the renderer, who read the monitored data, and, as the name suggests, rendered it onto the terminal. Because they were two separate processes (which was required, because they both had a while loop), their virtual memory space was not the same, so I had to learn about SHM, however, that was a while ago... So when I started working on Deploy again, and then I needed the same thing again, I was too lazy to look it up again, so I just copied it, pasted it, and moved on.

cherries(.)works Deploy is as you might have guessed a project for deployment. Pretty fun project for me, and very important to manage memory, and processes, especially for this project. I "copied" the architecture for Pulse to Deploy, however the only difference is that Deploy has 3 processes, one is the management process, WITHIN the management process the deployed project is also a separate process. And then the render process. So thats a lot of processes that share a specific chunk of memory. So I not only copied the architecture, but also the SHM method, exactly the way I did in Pulse.

However, I must have forgotten something, I wasnt that sure though, but the crash did happen, everytime I entered a config file that was invalid. I fiddled around with the return values, tried to exit early, and even then, the crash still somehow found its way in. Finally, the smoking gun revealed itself to me.

My own "stop" function, is helpful to me, as it kills the process, and then deletes the file that stored the PID within a folder. While that was running at the end of the main function, within the forked processes, the SHM updated the pids to "-1" if they were invalid. Let me just show you the first line of my stop function;

void stop(pid_t pid)
    kill(pid, SIGKILL);
...

Yeah, I did not know this, but running kill(-1, SIGKILL); in C (or Linux), means; send SIGKILL to every process the caller is permitted to signal, except itself... Well, my laptop did not crash then, I made it crash by either killing every single process, or until an error happened. So yeah, I added a check to see whether or not the pid is a negative number, if it is, I return. Problem was solved.

What that little rodeo taught me, was that C is really not forgiving. Especially, when it does something you told it to. I mean, I did tell it to "kill(-1, SIGKILL)", meaning kill everybody except me (in the computer). I gotta be more careful with the dangerous code that I write...

TLDR; Tried to make my own stop function, did not add a check for negative PIDs. Whole laptop exited....


r/C_Programming 5d ago

Easing memory management with a shared pointer

9 Upvotes

I recently developed a C (11 and newer) implementation of a thread-safe shared pointer with atomic reference counting:

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

It supports both strong and weak references and a swappable destructor. Initialization performs a single allocation.

If anyones interested, take a look. Feedback and bug reports very much welcome.


r/C_Programming 5d ago

forkpty error

7 Upvotes

i'm trying to make a terminal emulator but i can't figure out how to open a pty.

when i try to open a pty bouth forkpty from pty.h and my own implementation:

```c int init_pty() { int ptymaster_fd = posix_openpt(O_RDWR); if (ptymaster_fd == -1) { perror("failed to open pty master"); close(ptymaster_fd); return 1; }

if (grantpt(ptymaster_fd) == -1) {
    perror("failed to grantpt");
    close(ptymaster_fd);
    return 1;
}

if (unlockpt(ptymaster_fd) == -1) {
    perror("failed to unlockpt");
    close(ptymaster_fd);
    return 1;
}

char* ptyslave_name = ptsname(ptymaster_fd);
if (ptyslave_name == NULL) {
    perror("failed to get pty slave name");
    close(ptymaster_fd);
    return 1;
}

pid_t pid = fork();
if (pid != 0) {
    perror("fork");
    close(ptymaster_fd);
    return 1;
}

setsid();

int ptyslave_fd = open(ptyslave_name, O_RDWR);
if (ptyslave_fd == -1) {
    perror("failed to open pty slave");
    return 1;
}

ioctl(ptyslave_fd, TIOCSCTTY, 0);

dup2(ptyslave_fd, STDIN_FILENO);
dup2(ptyslave_fd, STDOUT_FILENO);
dup2(ptyslave_fd, STDERR_FILENO);

return ptymaster_fd;

} ```

fail when forking with the error directory not empty, ai says that it fails because /dev/pts is not empty but it's obviously trippin balls as usual =), so why does it fail then (?_?)


r/C_Programming 5d ago

CZ - An LLVM-based Compiler written in C for a Custom Programming Language

Thumbnail
github.com
4 Upvotes

I have been meaning to do this for a while, and I finally pulled the trigger on creating a new programming language called CZ (named because I randomly punched keys on the keyboard and that's what typed out).

I think LLVM API documentation is notoriously difficult, and even not as common for C programmers, so I decided to give it a go. I thought this might also be a good resource for people attempting to use LLVM C API.

Features roughly include:

  • Familiar usage to C. (if, for, while, etc.)
  • Function signatures are more "mathematical" notation than programming. (Maybe somewhat stolen from Haskell?)
  • Types are explicit. (No implicit type conversion or even type deduction). This would mean adding 3 and 4.5 are not allowed unless you explicitly convert one of them to the other type. (Kind of like rust).
  • References are explicit; a problem I had with rust is that sometimes references seem implicit. This is fine for most people, but sometimes I cannot get my head around as I'm not used to it yet.
  • Structs with default initialization values.
  • Because it also creates object file, you can actually link with C programs!

// fibo.cz

func fibo :: (n :: int32) -> int32 {

if (n <= 2) {

return 1;

}

return fibo(n-1) + fibo(n-2);

}

// main.c

#include <stdio.h>

int32_t fibo(int32_t); // Declaration of CZ function

int main() { for (int32_t i = 0; i < 10; i++) { printf("%d\n", fibo(i)); }

You can compile the cz file using my compiler, then with the generated object file, you can compile and link with main.c via GCC!

A few design choices were:

  • Make it minimalistic. No "magic" at all (looking at you C++)
  • Any allocation can fail, so there must be handling for that, without having to pull out my hair => "wrap goto statements whenever there is a null pointer from allocation"
  • String interning for optimization of string comparison.
  • Make a note of ownership model; not freeing is bad, but double freeing is even worse.
  • Robust yet workable type system: eg) const int32& = reference(const(int32)).

Note

* This was started off as a proof-of-concept, and is being redesigned. Not much more work will be done on this repo. (I am redesigning it at the moment, but in rust since I might be able to worry less about memory management and actually get working more quickly on features.)

* AI Usage: I kept the AI usage mostly for creating unit tests and architecture summary / documentation rather than writing code or designing; after all, this is for fun and for learning!

Thoughts and improvements are welcome! (Just note that I am not thinking of doing more work on this repo.)


r/C_Programming 6d ago

Why dynamic allocation of array gets memory address from heap?

49 Upvotes

let say I am using malloc to dynamically allocate a memory space with this line

Int user_defined_elements = 10 ;
// assume i got this from scanf

Int *p = malloc(
user_defined_elements * sizeof(int));

Right now the pointer refers to a chuck of memory address in heap I assume..I am trying to understand why heap instead of stack where local variables are saved.Is there anything special about heap?

Please be kind..I am python dev trying to learn c in my free team because I dont understand shit about cpython implementation..hahah..so i was like why not learn c and here I am


r/C_Programming 6d ago

Reliability Lessons From SQLite - Richard Hipp | SSW 2026

Thumbnail
youtube.com
39 Upvotes

r/C_Programming 6d ago

What should I do ? (Begginer help)

30 Upvotes

I'm currently in my second year of college, and I'm a little confused about what career direction I should take.

The part of programming I enjoy the most is lower-level/system-side work. I started with C and socket programming, building servers and learning how TCP/UDP networking works, and lately I've been going deeper into things like Linux networking, packet parsing, Ethernet/IP/ARP/ICMP, eBPF/XDP, AF\\_XDP, NIC queues, drivers, DMA, etc.

The problem is that almost nobody around me in college is doing this kind of work. Most people are focusing on web development, app development, AI/ML, or standard DSA preparation

I've also heard people say that "there aren't many jobs in low-level networking" or that networking careers mostly involve configuring routers/switches or working with networking hardware.

That's where I'm confused.

I definitely prefer programming/software engineering work. I'm not particularly interested in being a network administrator or doing primarily hardware/router configuration.

At the same time, my practical goal is still to graduate with a strong software engineering job. I don't want to spend the next 2–3 years going extremely deep into an interesting niche only to discover that there are almost no entry-level opportunities.

So I'd really appreciate advice from people working in this area:

What kinds of actual software engineering careers exist for someone who enjoys C, sockets, Linux networking, servers, eBPF/XDP, packet processing, etc.?

Are these mostly experienced/senior-level positions, or are there realistic entry-level opportunities as well?

What companies/industries typically hire engineers for this kind of work?

Should I continue going deep into networking/systems, or keep this as a specialization while also learning more conventional backend/software engineering?

What skills would you recommend building over the next 2–3 years if the goal is to be employable as a software engineer while still staying close to systems/network programming?

Are there particular open-source projects, projects of my own, internships, or areas of computer science that would be especially useful?

I'm not expecting to work specifically on XDP just because I'm learning it now. I'm mainly trying to understand whether the broader direction — systems programming + networking + performance-oriented software — is a sensible career path.


r/C_Programming 6d ago

I built a sensor dashboard in C where every metric, (name, unit, update rule) is just config data

4 Upvotes
Aether is a small C99 program that simulates sensor readings and renders them in a live Raylib dashboard. No frameworks — just Raylib for rendering, libyaml for config, and a handful of hand-rolled modules.                                        


What it does
                                                                                                                                                              - Sensors come entirely from a YAML config: each sensor has an arbitrary list of named metrics with units ( temperature (C), pressure (hPa) , ...). The display code has no idea what the metrics mean.                                                 

- Cards show each metric as a chip with its value, sparkline, and up/down change indicators                                                                         

- Click a card for a detail view: large trend line plus min/avg/max computed from a per-sensor ring buffer                                                             

- More sensors than fit the window? They paginate into numbered tabs (1 2 ...N), clickable or via Alt/Cmd + 1..N


- Settings modal (cogwheel, top right) toggles trend lines, animations, and          indicators at runtime                                                              


Architecture bits I'm happy with

- sensor/ — an open data model: a sensor is just an id + name + a list of 
{name, unit, value} metrics                                                               

- scheduler/ — only decides when. runTask(Task*)can't mutate anything it shouldn't 

- History/ — bounded ring buffers per sensor (drop-oldest), which the sparklines and stats read directly                                                                

- The UI renders from a registry (one authoritative struct per sensor), never from raw buffers — so duplicate/stale cards are impossible by construction              

- Layout math (tab capacity, page-list collapsing, range mapping) is extracted into a Raylib-free module with unit tests, including an exhaustive sweep of all pager states                                                                             


https://github.com/SalzDevs/Aether


Feedback welcome

r/C_Programming 7d ago

Writing generic code in C – Part 2

Thumbnail
thatonegamedev.com
33 Upvotes

After some comments on my previous post about writing generic code in C where people argue that this is “poor man’s overloading” I wanted to add a new technique that allows you to write real generic style code in C with the only drawback. You could even combine the technique from this lesson and the […]


r/C_Programming 6d ago

C is more efficient in AI memory than C++, measured

0 Upvotes

Having programmed in structures and the streaming way for the last 30 years (including for mainframes and old Unixes, even in FORTRAN and Pascal in the 90s) before OO arrived, I knew that frameworks are for people, to deal with complexity, not for the machines, and are now only an additional overhead for AI coders' reasoning. My brain was always thinking in terms of Turing machines, tapes and algorithms, pipelines of data, even punchcard stacks, where inputs are records/structs in databases and objects are just containers, preferring Ada83 over 95, MISRA C over C++, and in Java I used classes as containers for functions (data streams and functions come first). I ran tests to check my conjecture, and yes, it is measurably more efficient to program with AI agents in C and plain Java, keeping the context free for reasoning, than in C++, objects and Java frameworks. I haven't analysed web frameworks, but where we used plain JavaScript without them in production, we saw the same pattern, though we did not measure it; it is not in the paper. https://doi.org/10.5281/zenodo.22113993


r/C_Programming 7d ago

How to create a movie platform ?

0 Upvotes

I have been so fascinating of creating my own movie streaming platform. However, it doesn't mean that I will be using alone,but sharing with friends and mates. So, my question is what features will it be involved? Btw I am kinda beginner. If not enough with beginner level, please let me know the roadmap of building it

Thanks in advance..


r/C_Programming 8d ago

Question Best way to go over wireless file transferring

5 Upvotes

So I'm currently making an app in C and raylib to easily transfer roms from my main pc where I download them (I want to compile it both for windows and macos) to my arch pc-emulator console. I'm planning to make said pc usable with only a controller, and I figured making an app would be the best and most fun way to do it. I would prefer not running custom code on it, and would like to know the best (and easiest, since I'm still a beginner in C) way to handle the file transfer. Thanks in advance!


r/C_Programming 9d ago

Project I wrote a function plotter in C and Raylib

Enable HLS to view with audio, or disable this notification

233 Upvotes

It supports single-var equations, operands, brackets, implicit multiplication and some trigonometry and is based on shunting-yard parser / RPN evaluator I also made

For rendering, I implemented an adaptive function sampling (simple midpoint subdivision) - though it has some limitations, which I described on github. SSAA was also used to smooth plotted lines. As for optimization, plots are rendered only when zooming/panning and reused with a render texture when idle.

This is my first "useful" C program, though I've already had some experience with OpenGL (C++) as a part of my assignments

Feedback is much appreciated - https://github.com/kester4/cf2x


r/C_Programming 8d ago

Project shiori: a windows-first note taker

1 Upvotes

I started shiori as my small personal note-taking tool (because my Obsidian workflow always grew into larger documents). I also was looking to get back into C and improve my C23 coding skills.

The idea was to have a quick way to write something down without leaving the terminal. Notes and todos are stored in plain Markdown files, so I can read them without a tool and they integrate into my other note taking repository.

The workflow is plain and simple:

shiori add --topic development investigate UTF-8 path handling
shiori todo add --due tomorrow prepare release notes "#work"
shiori today

It has grown over the past weeks since I started and now supports a bit more than simple note taking (like topics and tags, todo workflows, etc.).

Some interesting parts for me have been to work on UTF-8 terminal input on Windows, dealing with a console input and ANSI escape codes and keeping my notes and files safe without overwriting them accidentally.

It is still an alpha and currently only supports Windows x64. I built it with clang and C23. I included unit and integrations tests and sanitizers to produce a as clean as possible code and binaries.

Repo link: https://github.com/lycis/shiori

AI disclosure: I use AI as a supporting tool for planning features, reviewing my ideas and implementation as well as helping with tests and docs. I write, understand, review and maintain the code myself as this is my "use it and learn" project.

Edit: I am curious to get feedback on the code and project itself, especially the usage of more "modern" C features.


r/C_Programming 8d ago

Question Why is this macro function's definition put in brackets?

0 Upvotes

I'm learning about macros from this website:

https://www.almabetter.com/bytes/articles/macros-in-c

The website talks about how macro functions can cause side effects that are not wanted.

The website provides the following example:

Pitfall: Macros can cause side effects if their arguments are evaluated multiple times. For example:

#define SQUARE(x) (x * x)
int result = SQUARE(++i);

Here, i will be incremented twice, leading to incorrect results.

Solution: Enclose the macro body in parentheses to ensure correct precedence. For example:

#define SQUARE(x) ((x) * (x))

Now, why does wrapping the definition of SQUARE(X) prevent i from being incremented twice?


r/C_Programming 9d ago

Question What's y'all choice for making UI for things you do in C?

70 Upvotes

I needed a UI for a project I was doing in C (which was basically a chat app built from the ground up), I needed a UI library and after getting a stroke trying to understand ncurses and CMake, failing at both, I had to use CGo and make a TUI with BubbleTea, but I wanted to get some popular choices for UI in C/any other language with FFI or smth.


r/C_Programming 9d ago

How LLVM turns C into machine code

39 Upvotes

Had some free time last week so I made a video on what actually happens after Clang turns C into LLVM IR.

It goes through LLVM IR, optimization passes, instruction selection, register allocation, and how the final machine instructions get produced.

I also use a small C example throughout, and compare it with equivalent Rust code that ends up producing the exact same x86 instructions.

Link for anyone interested

Feedback welcome :)


r/C_Programming 8d ago

Project I built SkollDice — an open-source, truly randomized dice roller and Discord bot written in pure C

0 Upvotes

Hello everyone! I'm a student who loves C and D&D!

I always found it troublesome that most dice generators rely on pseudo-random number generators. So, I decided to solve this problem by myself!

Over the last few weeks, I created a desktop app using LVGL for the GUI and Concord for a Discord bot to generate SkollDice my first truly open-source code. It's a truly random dice roller that, /urandom on POSIX systems and RtlGenRandom on Windows produces normalized random numbers. To be more precised each number (each result) is extracted from urandom, and through the use of the simple discard method the result is then normalized. I'm currently developing the smartphone version, hoping to use as much C as possible. Any ideas on how to do it?

AI usage: I personally created the program. The project was both an experiment and an excuse to study more C. I used AI to search for the simple discard method (the method used to normalize the random number generated from /dev/urandom) and to help me explain how it works. I then personally created the code, and if you want, I can explain it more precisely in a comment.

On the other hand, I then used AI to search for libraries for GUI and Discord API, such as LVGL and CONCORD. Then the last use was for debugging and quickly creating functions or simple setups like "How can I create a grid with 2 elements?" and then I used this example to change or apply it to my structure.

The real 'sloppy' part was the CMake because this was my first open-source project, and I discovered (through AI search) the possibility to create different executables for different OS. I really enjoyed the idea, so I tried to organize the project to be useful and distributed to all possible people, both coders (who can git clone and use it) and normal D&D or RPG players (that want just an executable to download and use).

Here the official links of the program:

official website: https://skollwarynz.github.io/SkollDice/

official repo on codeberg: https://codeberg.org/Skollwarynz/SkollDice

github mirror: https://github.com/Skollwarynz/SkollDice


r/C_Programming 9d ago

Struct pointer casting and inheritance : can it work ?

5 Upvotes

Hello everyone, this is my first post here.

I am working on a UI library in order to learn the concepts behind it, and to be able to create most of my desktop applications. Having implemented widget selection with the mouse (using the mouse coordinates to find the widget in the tree), I decided to move on to event handling.

However, I'm not sure at all of how to proceed, and I am having problems with struct pointer casting .

I have a base struct Widget with a function pointer to event handling functions.

typedef struct Widget {
  Rect bounds;             // Actual bounds
  Rect clip;               // Clipping rectangle (usually the parent)
  bool active;
  [...]
  int (*eventHandler)(Widget* w);
};

Every derived widget struct has a Widget* as 1st member, and each type has its Create...() function, where the correct event handler is assigned.

typedef struct Frame {
  Widget* widget;
  bool root;
}

Frame* CreateFrame(int x, int y, int w, int h, bool root) {
  Frame* f = (Frame*)malloc(sizeof(Frame));
  [...]
  f->widget->eventHandler = &FrameHandleEvents;
  return f;
}

To get back all the properties when handling events despite eventHandler taking a Widget*, i attempted to cast back to the derived struct :

int FrameHandleEvents(Widget* widget){
  Frame* frame = (Frame*)widget; 
  printf("Frame event!, root = %d\n", frame->root ? 1 : 0);
  return 0;
}

Is this even allowed in C, or am I misusing casts ? The output of print is also garbage data :

Frame event!, root = 244

Thanks for your advice


r/C_Programming 10d ago

one compiler failing, other compiler running fine

4 Upvotes

I've been using emacs to follow some tutorials which has been working great, but switch to sublime text and now getting compile error. or, i assume its a problem with the compiler since this code runs in emacs but not in sublime text. the relevant stuff

this is the exact same in emacs and sublime:
_mm_store_si128((PIXEL32*)gBackBuffer.Memory + x, *pColor);

sublime is throwing this error:

error: passing argument 1 of '_mm_store_si128' from incompatible pointer type [-Wincompatible-pointer-types]

391 | _mm_store_si128((PIXEL32*)gBackBuffer.Memory + x, *pColor);

the sublime build file:

"cmd": ["gcc", "-Wall", "${file}", "-o", "${file_path}/${file_base_name}"],

"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",

"working_dir": "${file_path}",

"selector": "source.c",

"variants":

[

{

"name": "Run",

"shell_cmd": "gcc -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""

}

]

}

And the emacs build command:

x86_64-w64-mingw32-gcc -g hello.c -o ./hello.exe -lgdi32

I am very noobish to these kinds of things, especially this SIMD stuff, so Im just assuming this is a compiler thing


r/C_Programming 9d ago

Discussion C language is wild: due to integer overflow, nearly half of the numbers squared become negative.

0 Upvotes

This started with a question from CSAPP Problem 2.44: (x * x) >= 0; which asks to find a counterexample that evaluates to 0,or prove that all number evaluate to 1.(part,32bit)

The official solution provides only 65535, but I found many more.

To test my results, I wrote a C program to find all such number. ```c

include <stdio.h>

include <limits.h>

int main() { // Ideal result: numbers whose squares are less than 0. // Written to file in the following format: // start_num1 to end_num1 total: total_num1 // start_num2 to end_num2 total: total_num2 // ... // total: total_all

FILE *file = fopen("lessthan0.md","w");
int start = 0;
int end = 0;
int total = 0;
int total_tmp = 0;

for (int i = -INT_MAX -1 ; i <= INT_MAX; i++) {
    unsigned ui = (unsigned)i;
    int result = (int)(ui * ui);


    if (result < 0) {
        total++;
        total_tmp++;
        total_tmp == 1 ? start = i : 1;
        total_tmp == 1 ? end = i : 1;
        i == end + 1 ? end = i : 1;
    }

    if (i == end + 1) {
        start == end ? fprintf(file,"%d    total: %d\n",start,total_tmp) : fprintf(file, "%d to %d    total: %d\n",start, end,total_tmp);
        total_tmp = 0;
    }

    if (i == INT_MAX) {
        fprintf(file,"total: %d",total);
        break;
    }

}

fclose(file);

} ```

So I get this: ```sh ls -lh lessthan0.md -rw-r--r-- 1 kyee users 31G Aug 23 18:50 lessthan0.md

ls -l # run twice -rw-r--r-- 1 kyee users 32288890271 Aug 23 18:50 lessthan0_1.md -rw-r--r-- 1 kyee users 32288890271 Aug 23 20:27 lessthan0.md

wc -l lessthan0.md 1073741824 lessthan0.md

head lessthan0.md -2147437307 to -2147418113 total: 19195 -2147403383 to -2147390967 total: 12417 -2147380026 to -2147370137 total: 9890 -2147361041 to -2147352577 total: 8465 -2147344625 to -2147337106 total: 7520 -2147329952 to -2147323119 total: 6834 -2147316563 to -2147310257 total: 6307 -2147304170 to -2147298285 total: 5886 -2147292579 to -2147287041 total: 5539 -2147281652 to -2147276405 total: 5248

sed -n "470063416,470063426p" lessthan0.md -535664087 to -535664086 total: 2 -535664083 to -535664082 total: 2 -535664079 to -535664078 total: 2 -535664075 to -535664074 total: 2 -535664071 to -535664070 total: 2 -535664067 to -535664066 total: 2 -535664063 to -535664062 total: 2 -535664059 to -535664058 total: 2 -535664055 to -535664054 total: 2 -535664051 to -535664050 total: 2 -535664047 to -535664046 total: 2

tail -n 10 lessthan0.md 2147287041 to 2147292579 total: 5539 2147298285 to 2147304170 total: 5886 2147310257 to 2147316563 total: 6307 2147323119 to 2147329952 total: 6834 2147337106 to 2147344625 total: 7520 2147352577 to 2147361041 total: 8465 2147370137 to 2147380026 total: 9890 2147390967 to 2147403383 total: 12417 2147418113 to 2147437307 total: 19195 total: 2147418112

```

I noticed symmetry between the begging and end of the output.Can someone explain why this happens?

2147418112 / 232 = 0.4999847412109375 This accounts for nearly half of all 32-bit signed integers.


r/C_Programming 11d ago

Question Getting stuck at libraries and api’s

14 Upvotes

So C is technically my first programming language I’m learning. I’ve messed around in python but never actually go deep into it or anything.

I’ve been learning C for the past few days now and I already pretty much know most of the basics. I learned pointers and mallic in a day and I learned structs, macros, for loops, while loops, functions, all of that stuff, but… the moment any library other than the basics like stdio or stdlib come into play I’m lost.

It’s like I’m looking at a whole other language. Like I’ll look for solutions to problems and it seems as if they are just pulled out of thin air and when I try to read ANY documentation for ANY library I’m also lost because either there is little to no documentation or it’s just stupid and things aren’t well explained.

Is there a way I can fix this? I was doing so well and now I’m at this block because of libraries. If I could get pasted this hurtle I could learn c in less than a month easily, and that’s the same in any other language. This problem isn’t exclusive to C.


r/C_Programming 10d ago

Discussion Turbo C still force on us to learn C

0 Upvotes

Like I know that using turbo c to learn c is going to set me back,but my college program head thinks its the best way for us to learn c? so I do want to hear your thoughts in this(btw cause I'm rebellious I use gcc and nvim to do most of m work and actually learn). Again thank you for sharing your thoughts!

Edit: after looking at the comments It seems I a little bit naive but Ill put you re advice into heart! Cheers!


r/C_Programming 13d ago

Hello World

87 Upvotes

I have found my people!! Hello guys I am a college student (mechanical engineering) and I was introduced to C in a mandatory programming course and C has been the best thing that has happened in my life. I had done programming before on java and python before and frankly I hated it , it was not really fun and it was tedious instead. So I had thought I hated CS but after coding in C and learning the things behind the abstractions i quite frankly fell in love with low level programming, it was the first time I got a passion for something and i spent the entire following summer digging up materials on it like learning computer architecture and learning to read and write Assembly and now I am learning Virtualisation and planning to start my first major project on C.

So in that note, let me ask you something:

What is your favourite project you have done in C?


r/C_Programming 12d ago

Project 3D Library using SDL3

Thumbnail
github.com
24 Upvotes

This project has taken a long time.

It took me about a week to learn the concepts behind 3D projection and transformations in euclidean space. Then it took me over a week to write out the LaTeX documentation that presented my knowledge in a way that would help a user of this library. As you can see, the overwhelming majority of the code committed to this repo is in LaTeX.

The implementation of the 3D rendering framework was relatively simple once I fully understood the mathematics. This only took a couple days, and it helps to have some familiarity with C going in.

I look forward to improving this project by building a separate homogeneous coordinate library that will replace pnt.c. I also need to tackle surface rendering using SDL_RenderGeometry() and implement 3D surface occlusion. I suppose what I'm left with for now are a few big questions.

How prohibitive is heap-allocation for performance in graphics applications? I went with dynamic allocation to preserve encapsulation so that header files didn't give the user access to data that would destroy library functionality when altered. However, given the fact that querying free memory at runtime for thousands of data points slows a program significantly, I'm having second thoughts.

Also, is there a convenient way to push all of the calculations needed for 3D transformations onto the GPU? This seems like something I shouldn't handle entirely in software.

I'll hear out any feedback or suggestions in the comments!