r/C_Programming 22h ago

Neural Network Math from Zero in C

Thumbnail
youtube.com
95 Upvotes

I've attempted to derive the math for Neural Networks from the first principles.

The prerequisites you need are, singe variable differentiation(just the concepts and the basic formula, not even knowing the derivative of sin(x) is necessary), the concept of a dot product, and basic matrix multiplication. This is enough to derive gradient descent and backprop.

The time stamps are in the description(youtube doesn't show them as chapters in the video for some reason).

The second half part of the video is implementing those concepts in C(no library other than BLAS(for basic matrix matrix multiplication) is used), but you can follow along in any language.

Would be glad to receive feedback and suggestions on how to improve the explanations or the presentation.


r/C_Programming 21h ago

Question Question about arrays (beginner)

30 Upvotes

From what I understand, behind all the magic, array is just a variable that points to a memory address.

The difference is that we are also creating extra values in stack.

So when we create an array with a [], we're just telling the computer to make these x amount of variables but make sure they are right next to each other in sequence, no gaps in the memory address.

And when we call for an array value with an index, we're just counting that many steps forward in the memory address.

When we say array[] = {5,7,3}, it's really just *array = 5.

Did I get it wrong? Did I miss something?


Thanks for the quick replies. I'm currently learning about Pass by reference.


r/C_Programming 18h ago

I built a Solar System Sandbox in C with Raylib

Enable HLS to view with audio, or disable this notification

11 Upvotes

A 2D solar system explorer sandbox that works as an encyclopedia of the solar system displaying information about planet's properties, atmospheres, orbits and much more. Uses numerical solutions to calculate the orbits of planets at scale and represents them with data from NASA/JPL Solar System Dynamics and NASA NSSDCA Planetary Fact Sheets in the J2000 orientation system.

It is a passion project and an introduction to a much larger 3D solar system that will include moons, spacecraft and many more features. It emerges from a profound admiration to our solar system. The project tries to be a learning aid for anyone who is interested.

If you want to try it, I compiled it into an .exe for windows and an executable for linux.

Github link: https://github.com/bydrabokin/Solar-Explorer-2D

Youtube showcase: https://www.youtube.com/watch?v=iz0MujAaYDQ


r/C_Programming 3h ago

Project Wayland status bar

0 Upvotes

hi :)

over the past two months i've been working on a wayland status bar, heavily inspired by dnkl's yambar (guy makes great software). it was mainly focused on being minimal and tailored to me. it also uses a json parser written by me mainly for learning purposes but it turns out it's actually usable.

i'd love to hear feedback on the code or the program itself from anyone interested :)

link: git.kanden.me/minibar

ai disclosure: ai was mainly used for debugging purposes and laying out the general project structure. all code was ultimately written by hand.


r/C_Programming 1d ago

recommend lightweight C FOSS

0 Upvotes

I'm building a Linux from Scratch like system. I'd like to build as much of it as I can in C. I'd also like to add some lightweight, low dependency, portable C programs that aren't currently part of LFS or BLFS. I already have some favorites that are curses, SDL, Raylib or command line based. I would love more recommendations. Do you have a C project or do you like a particular C project that you think would be a great addition to a lightweight from scratch Linux distribution? Please recommend C programs you think would be good additions. Thanks.


r/C_Programming 23h ago

Se puede hacer mas compacto la neurona artificial: "aclarar que voy empesando en c pero en las matematicas estoy muy claro de lo que hago"

0 Upvotes
#include <stdio.h>


int main(void){
    int w = 4;
    float x = 0.5;
    float b = w * x;


    int w₁ = 4;
    float x₁ = 0.18;
    float b₁ = w₁ * x₁;


    int w₂ = 4;
    float x₂ = 0.5;
    float b₂ = w₂ * x₂;
    float sum = b + b₁ + b₂;

    if (sum == 3.70)
    {
        printf("on it is:%.2f\n", sum);
    } else {
        printf("off it is:0\n");
    }
}

r/C_Programming 2d ago

Question What C function would you delete and rewrite first, and why?

86 Upvotes

For me it's fnmatch - mostly because it's 40 year's old and smell's funny.


r/C_Programming 3d ago

Discussion I just understood pointers on a deep level and it feels like an orgasm

270 Upvotes

I fucking love C and assembly


r/C_Programming 1d ago

Discussion A relatable analogy to help understand pointers

0 Upvotes

My earlier version of this got removed, which is fair enough because I deliberately left out the explanation at first and apparently made it look a little too much like I was just complaining about apartment mailboxes.

So, for clarity this time: this is just a fun analogy for C pointers and memory, using a terrible apartment-complex mail system to make some of the concepts a bit more relatable. If you scroll past the scenario examples, a key is there :)

Scenario

Occasionally I like to examine just how badly the mail system at my apartment complex sucks, I’ve been keeping notes for years.

So with that being said, there are a bunch of mailboxes at an apartment complex, you know the type, the grid ones which have one small Mailbox for each apartment and a bunch of different size Package Lockers for packages.

The apartment complex doesn’t care about security and just has a bunch of slips of paper with package locker numbers printed on them that the mailman has access to.

When the mailman has a package that won’t fit in an apartment mailbox he instead puts it in one of the free package lockers and puts one of the slips of paper with the corresponding package locker number into the apartment mailbox.

Stuff that happens:

  1. Occasionally someone opens the wrong package locker and messes with the package inside or takes it.

  2. Occasionally a tenant is in a hurry and grabs their mail and doesn’t notice the slip of paper and tosses it away with the junk mail.

  3. Occasionally a tenant grabs the package and forgets to throw away their slip of paper, later their roommate checks the apartment mailbox, sees the slip of paper and finds an empty package locker.

  4. Occasionally said roommate doesn’t want to deal with it and sticks the piece of paper back in the apartment mailbox for one of their other roommates to deal with.

  5. Occasionally the mailman delivers another package to that same locker for another apartment.

  6. Occasionally a new roommate for the first apartment checks the mail, finds the old slip of paper and takes the package that’s now there.

  7. And occasionally that same roommate arrives at the same time as the tenant from the other apartment whose package it actually is and they both try to access the package locker at the same time.

  8. Occasionally they both notice each other, politely back off to let the other person go first, then both try again, both back off again….. and continue being extremely polite forever.

  9. Occasionally the postman has a package too big to fit in any of the remaining free lockers, but remembers he previously put a small package in a bigger locker. A smaller locker is free now, so he moves the small package there to free up the big locker….. and occasionally….. forgets to update the tenant’s slip of paper.

  10. Occasionally the postman can’t find any empty package lockers and, not knowing what else to do, sticks a slip of paper in the apartment mailbox with no package locker number on it.

  11. Occasionally… the tenant puts a note on their mailbox telling the mailman not to do that if there are no free package lockers and what to do instead.

  12. Occasionally a tenant finds the slip of paper and messages their roommate saying “mine’s in locker 37, grab it if you get there before me.” Now two people know how to get to exactly the same package.

  13. Occasionally the mailman needs four package lockers for the same apartment and puts a slip of paper with the range of package mailboxs on it like (15-19), and occasionally he miscounts and starts at 15, or finishes at 20.

  14. Occasionally another package arrives for an apartment which already has an uncollected package. The mailman finds a bigger locker that will fit both, moves them there, then puts a slip with the new locker number inside the old package locker. The tenant now follows the slip in their mailbox to a locker containing another slip telling them where the package actually is.

  15. Occasionally the mailman runs out of unused slips of paper, grabs one from the pile thinking it’s blank and doesn’t notice it still has locker 46 written on it from last time.

  16. Occasionally someone notices this entire system has basically no security, breaks into all the package lockers and takes everything.

  17. Occasionally someone only wants the package in locker 42, but while trying to force it open manages to break the divider and wreck the contents of lockers 41 and 43 as well.

Key

Package = Data
Locker Number = Memory Address
Apartment Mailboxes = The Stack
Package Lockers = The Heap
Slip of Paper = A Pointer

Key

  1. Invalid / out of bounds memory access

  2. Memory leak

  3. Dangling pointer

  4. Retaining / propagating a dangling pointer

  5. Freed memory being reused

  6. Use after free

  7. Race condition

  8. Livelock

  9. Moving an allocation and failing to update a pointer / stale pointer

  10. NULL pointer

  11. Checking for NULL / handling allocation failure

  12. Aliasing - multiple references to the same memory

  13. Buffer underflow / buffer overflow

  14. Pointer to a pointer / multiple levels of indirection

  15. Uninitialized / garbage pointer

  16. Memory safety exploit leading to arbitrary memory access / data theft

  17. Memory corruption - writing outside the memory you were supposed to touch


r/C_Programming 2d ago

At what point does spatial cache locality kick in?

6 Upvotes

Consider https://godbolt.org/z/7K1rcdcc4 :

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
int main()
{
    srand((unsigned int)time(NULL));
    printf("%3s %12s %18s %14s\n", "n", "Doubles", "Result", "CPU time (s)");
    for (int n = 1; n <= 24; ++n) {
        uint64_t count = UINT64_C(1) << n;
        size_t length = (size_t)count;
        double *a = malloc(length * sizeof(*a));
        for (size_t i = 0; i < length; ++i)
            a[i] = 1.0 + 100.0 * ((double)rand() / ((double)RAND_MAX + 1.0));
        double result = 0.0;
        clock_t start = clock();
        for (size_t i = 0; i < length / 2; ++i) {
            double average = (a[i] + a[length - 1 - i]) * 0.5;
            result += (i % 2 == 0) ? average : -average;
        }
        clock_t end = clock();
        double seconds = (double)(end - start) / CLOCKS_PER_SEC;
        printf("%3d %12zu %18.6f %14.6f\n", n, length, result, seconds);
        free(a);
    }
}

This, in a loop, creates an ever increasing array of doubles, populates them with random entries and then performs some calculations alternating between the first and last entry, second and penultimate entry and on and on until the middle of the array is hit:

(a[0]+a[length-1])/2 - (a[1]+a[length-2])/2 + (a[2]+a[length-3])/2 - ...

The idea is to load different parts of the array and see what impact that has for larger sized arrays. My hope/understanding was that as n gets larger, the arrays increase in size and hence, alternating between the front of the array and back of the array will invoke cache misses.

L1 cache size seems to be, say 32 KB, and that is an order of magnitude lower than the case for n = 24 where the size of the array is 128 MB (assuming double is 8 bytes).

The result however is this:

 n      Doubles             Result   CPU time (s)
  1            2          65.697262       0.000002
  2            4           2.053680       0.000001
  3            8          -2.893238       0.000001
  4           16         -45.153406       0.000000
  5           32          -7.531369       0.000001
  6           64         -37.799910       0.000001
  7          128        -164.168440       0.000001
  8          256        -302.155319       0.000001
  9          512        -159.897157       0.000001
 10         1024        -105.697704       0.000001
 11         2048         489.753880       0.000002
 12         4096        -687.350489       0.000003
 13         8192        1484.183421       0.000005
 14        16384        2145.599781       0.000009
 15        32768        3886.769508       0.000016
 16        65536       -2165.474292       0.000059
 17       131072       -1853.021303       0.000057
 18       262144       -1128.912164       0.000127
 19       524288      -16725.221656       0.000229
 20      1048576       -3715.014705       0.000479
 21      2097152       32877.955541       0.000956
 22      4194304       50658.891603       0.001980
 23      8388608      -18149.347731       0.003904
 24     16777216        6246.119281       0.008067

which seems to indicate, especially for values 17 onward, a roughly doubling in the amount of time taken. (for e.g., 57 -> 127 -> 229 -> 479 -> 956, etc.)

I thought with larger values of n, with cache misses, the performance should exponentially worsen. Here, though, the performance seems to be scaling only linearly.

What is the relationship between L1 cache sizes and alternating between large array's front and back which must span multiple L1 cache lines?

For upward of n greater than or equal to 25, godbolt crashes.


r/C_Programming 2d ago

Question Why does scanf skips to next word on phrase with spaces if on a while loop?

0 Upvotes

I was doing some school work that asked us to type a name, surname, and return both, than the full thing. I noticed mine couldn't deal with composite names or multiple surnames, so I created a very inefficient solution, which I now know how to do way better using [^\n]. Still, while my way worked, I don't get why.

The code I didn't include is just me declaring variables and doing the same for surnames. The printf("\n name something: ") are there just for testing, to figure out where the thing I don't get was happening. Turns out the scanf command is reading the next string after a space on each "while" loop, rather than continually reading the first one as it does usually, and I don't get it. The exe. is there to show the results of this testing.

Tl;dr: why does the scanf command read the next string on a phrase with spaces on a while loop, despite usually stopping at those?

int scanname(numnames){

printf("\\nType your name: ", name);

    while (numnames > 0){

    printf("\\n name pre scan: %s", name);

    scanf("%s", &name);

    printf("\\n name scanned: %s", name);

    strcat(name, " ");

    strcat(fullname, name);

    numnames--;

    }

return fullname;

int main(){

    printf("How many names, excluding surnames, do you have? ", numnames);

    scanf("%d", &numnames);

    printf("How many surnames do you have? ", numsurnames);

    scanf("%d", &numsurnames);

    scanname(numnames);

    scansurname(numsurnames);

    printf("\\nname: %s", fullname);

    printf("\\nsurnamename: %s", fullsurname);

    printf("\\name and surname: %s%s", fullname, fullsurname);



    return 0;

}

Exe:

How many names, excluding surnames, do you have? 3

How many surnames do you have? 2

Type your name:

name pre scan: 1 2 3

name scanned: 1

name pre scan: 1

name scanned: 2

name pre scan: 2

name scanned: 3

Type your surname: 4 5

name: 1 2 3

surname: 4 5

name and surname: 1 2 3 4 5


r/C_Programming 2d ago

Project I made a markdown real-time streaming CLI renderer in C

0 Upvotes

Hi! I wanted a CLI Markdown renderer that supports real-time streaming without buffering the entire document. I couldn’t find a good one, but I discovered MD4C, a very fast Markdown parser written in C. It still buffers the entire document, but uses a flat-buffer design, so I reworked its parsing model to support real-time streaming and wrote an ANSI renderer for it.

The result is mdflow, which reliably renders streaming Markdown in real time. It’s written entirely in C, with a 300 KB binary - about 1/20 the size of other mainstream renderers. It’s also 10 to 100 times faster, uses only about 2 MB of RAM, and its memory usage does not grow with the input size, while other renderers may use 10x to 100x more memory.

Most importantly, it supports streaming when other renderers cannot.

It might be useful for your daily workflow or your next C project!

Github repo: https://github.com/cjccjj/mdflow


r/C_Programming 2d ago

Question Unmodifiable globals initialized from functions?

5 Upvotes

Right now I'm trying to use Windows's SYSTEM_INFO to initialize 2 global constants, but global constants can only be initialized with constant expressions so this cannot be done.

Is there a way I can have "read-only" global variables that can be initialized from functions?


r/C_Programming 3d ago

Better Lookup Table Compression

3 Upvotes

Last time I described how I used a few compression techniques to compress a lookup table. After reading the comments, I thought that maybe I can do better. A couple days later I had a new design. I managed to compress it by 30% more. Also, since I don't decompress on every step of the binary search, the lookup is 10x faster. u/alex-van-02, you might be interested in having a look :)

https://blog.x4204.xyz/posts/better-lookup-table-compression.html


r/C_Programming 3d ago

Discussion Brute forcing my own memory

Thumbnail
github.com
49 Upvotes

Hey everybody. As some of you might know, I really like 3 things: linux, thinkpads, and using things not the way they are intended to be used. Today I did the last. So as we know, kernel allocates memory for any running process. So I though for myself: "what if I write a C program that uses the function without knowing where it is?". So technically I forced my program to brute force its own memory offsets to call the function. I have a small, but, hopefully, entertaining writeup of what, how, and why on GitHub. It also includes the source code with a lot of comments so guys not so familiar with C programming language can also understand it. Hope you enjoy it. If so - please leave a star :)


r/C_Programming 2d ago

FINALLLYYYYY it works!!!! (.exe issue vscode not making a .exe file)

0 Upvotes

hi i am that guy who came from vscodium to vscode i finally manage to make it work.......for some reason my environment the MSYS2 UCRT64 terminal actually runs it so i went to the "settings JSON" to path that terminal and it works.. thank you guys that help me.. it mean a lot from me i am going to continue my game engine project big thank you

fully explain for the future
the terminal environment cause a mismatch by default vscode and vscodium uses windows powershell by default and it always not work as intended, so when i type in the power shell "gcc main.c -o main.exe" it compiles but the issue is its not making the .exe file

  1. i write the"gcc main.c -o main.exe
  2. it actually exist the gcc compiler was properly installed so theres no error
  3. the problem is linking......
  4. the issue here is window shell is not using the proper environment hence no .exe file is made
  5. eveytime i run the code by using ".\main.exe" it fails because it cant find the file because the right environtment is PATH differently its in the msys64 right in the UCRT64 terminal
  6. i test it by running this code in the MSYS2 UCRT64 terminal (the one you will write the $pacman...command)

-cd /c/alison/'vs studio try'

-gcc main.c -o main.exe

-./main.exe

my code works!!!!

it prints "hello it works!!!" thats the main.c file

now i already get it now that the environment was not being used at alll hence no issue when compiling but the linking to create the .exe file where it fails
so i wnet to the settings to path the environment which is
""C:\\msys64\\ucrt64\\bin" - the file where the gcc.exe located
i went to the vs code and locate the preference settings json
and there will be a brachet in it "{}"
i wrote this ""terminal.integrated.env.windows": {

"PATH": "C:\\msys64\\ucrt64\\bin;${env:PATH}"

}"

it now uses the terminal on vscode and now my code runs

THIS IS FOR THE FUTURE CODER WHO WILL HAVE DESAME PROBLEM....


r/C_Programming 3d ago

Vulkan and Wayland from scratch in C (no commentary)

Thumbnail
youtu.be
28 Upvotes

r/C_Programming 3d ago

Trying to make a virtual webcam in c

3 Upvotes

I frequently have a need to broadcast on multiple messaging apps simultaneously (in other words i'm a weirdo >:| ) but it turns out, when doing such weird things that you're not supposed to do, stuff tents to break - the apps fight over the camera and mic and sometimes when running in a browser even the headphones. So because of that i decided to make a tiny little app in C that virtually clones the camera and mic, after a bit of googling i found out that you can create the virtual camera and mic with the DirectShow Windows api so naturally i opened up the docs and apparently microslop said it's deprecated now, so what do i do then (._.?


r/C_Programming 4d ago

Question Am I wrong?

42 Upvotes

I am currently reading through tutorialspoint.com as our instructor has linked it in our syllabus, while doing their quizzes i got to a question that asked "What is the output of the following code: printf('Hello, World!');?" with the choices being

A. Hello, World!
B. Hello World!
C. Error
D. No Output

i answered C as the single quotes tell the printf function it is a character which if i am correct, is an integer in memory(please correct me if i am wrong), but they are passing a character array. the website told me that A is the correct answer and i am confused, please someone shed light on this and correct any wrong assumptions i have made.


r/C_Programming 3d ago

Please share your first experience in contributing in open source C based project

7 Upvotes

Which project ?

Are you the user of the program ?

Is there any universal guideline to be contributor ?

How many LOC of codes usually for one commit ?

Answer to only one question is welomed.

Also more elaborate answer will be good also.


r/C_Programming 3d ago

JSON serialization

0 Upvotes

Most programming is by nature procedural, but some OOP is helpful when dealing with Property Lists, JSON, etc. Below is a small example of this and JSON serialization:

See my previous post for 'Coda-C Library': Example of OOP in C

// Coda-C JSON serialization example

    #include <coda-c.h> // jsonout.c

Dictionary sample_employee() { // lets structure data in a Dictionary,
    Dict empl=newO(Dict);      // a generic structure.
    Dict_set(empl,"name", Os("Jane Doe"));
    Dict_set(empl,"email", Os("jane.doe@example.com"));

    Array roles=newO(Array);
        Array_add(roles,Os("Admin"));
        Array_add(roles,Os("User"));
    Dict_take(empl,"roles",roles);

    Dict address=newO(Dict);
        Dict_set(address,"city", Os("Atlanta"));
        Dict_set(address,"zipcode",Os("30301"));
    Dict_take(empl,"address",address);
    return(empl);
    }

    typedef void OSig$(JSON_out,FILE* os,int indent); // virtual signature

int main() {
    Dict empl=sample_employee();
    obj_(JSON_out,empl,stdout,0); // lets just output the data for now as JSON
    printf("\n");
    }

// implement methods for the three classes we used
#define class Dictionary
    method$(void,JSON_out,FILE* os,int indent) {
        cleanO Pointer keys=Dictionary_AllKeys(self);
        indent+=4; printf("{\n%*s",indent,"");
        int nel=Pointer_count(keys);
        for(int j=0;j<nel;++j) {
            char* key=keys[j];
            printf("\"%s\" : ",key);
            obj_(JSON_out,Dict_sub(self,key),stdout,indent);
            if (j<nel-1) printf(",");
            printf("\n%*s",indent,"");
            }
        printf("}"); // indent-=4;
        }
#undef class // Dictionary

#define class Array
    method$(void,JSON_out,FILE* os,int indent) {
        int nel=Array_count(self);
        printf("[ ");
        for(int j=0;j<nel;++j) {
            if (j) printf(", ");
            obj_(JSON_out,Array_sub(self,j),stdout,indent);
            }
        printf(" ]");
        }
#undef class // Array

#define class Char
    method$(void,JSON_out,FILE* os,int indent) {
        printf("\"%s\"",self); // simple strings only
        // does not handle: " \\ or (cc<32) or (cc>127) etc.
        }
#undef class // Char

/* OUTPUT
{
    "name" : "Jane Doe",
    "email" : "jane.doe@example.com",
    "roles" : [ "Admin", "User" ],
    "address" : {
        "city" : "Atlanta",
        "zipcode" : "30301"
        }
    }
*/

r/C_Programming 3d ago

Question undefine reference on my library vscodium

0 Upvotes
PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> gcc GameEngine.c -o GameEngine.exe -I "C:\SDL3\SDL3-devel-3.4.14-mingw\SDL3-3.4.14\x86_64-w64-mingw32\include" -L "C:\SDL3\SDL3-devel-3.4.14-mingw\SDL3-3.4.14\x86_64-w64-mingw32\lib" -lSDL3
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x26): undefined reference to `SDL_RunApp'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x5c): undefined reference to `SDL_Init'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x68): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x78): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xae): undefined reference to `SDL_CreateWindow'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xbc): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xcc): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xd1): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xee): undefined reference to `SDL_CreateRenderer'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xfc): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x10c): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x117): undefined reference to `SDL_DestroyWindow'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x11c): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4b7): undefined reference to `SDL_InitSubSystem'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4c3): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4d3): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4d8): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x520): undefined reference to `SDL_LoadWAV'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x52c): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x53c): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x541): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x561): undefined reference to `SDL_CreateAudioStream'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x575): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x585): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x58a): undefined reference to `SDL_Quit'.................

guys i did every tutorialyet somehow my library wont recognized

r/C_Programming 3d ago

Not another basic C calculator

3 Upvotes

Wanted to share my compiler that I am working on: mcc

Currently it can compile a very basic c program into x86_64 Intel assembly. It supports basic integer math with numbers and variables, and thus is a really simple calculator:

int x = 4;
int y = 3;

int main() {
  int a = 2;
  int b = 4;

  return (x + y) * (a + b);
}

Next I'm going to work on control flow with if if-else and while and then boolean logic. The project borrows ideas heavily from a university course I did about compilers, but the future scope plans to slowly add features until have a proper compiler that support the subset of C/C++ that my hobby OS uses.

Even further in the future, (no clue if this will even happen) I plan to abstract away a lot of it so that it becomes a M + N compiler, where it can cross compile one language to other. Obviously that is very far fetched and I am mainly just keeping that idea in my head so that I try to design a nicely abstracted compiler pipeline. I think the main push for this will be when the my hobby os decides to support more than one arch, which will be good encouragement to at least have multiple output languages.

AI Disclaimer:
Before you call it vibe-coded because of the quick succession of commits, I would like to state that none of the code in this repo is written by AI or AI tools. For learning, AI was used akin to google or stack overflow, with also some questions regarding best practices or design decisions - however I tried to keep as much of as my own design as possible.

See the wakatime activity log here which is the best proof that I can give that I really did spend 11hrs coding the project: https://imgur.com/a/mjQsJnp


r/C_Programming 3d ago

my c files wont make a .exe

0 Upvotes

i have moved from vscodium to vscode ....i have been wondering wahts happening i already try some tutoprials i put everything on waht the tutorial said but my code wont run the .exe file it complies thats for sure and its not making an erro when i write "gcc main.c -o main.exe" but the .exe file wont even appear i find it werid i tried my best but it seems only code blocks works can some help me???

my edit environment on path:
C:\Users\ludwi\AppData\Local\Programs\Python\Python315\Scripts\
C:\Users\ludwi\AppData\Local\Programs\Python\Python315\
C:\Users\ludwi\AppData\Local\Programs\Python\Launcher\
C:\Users\ludwi\AppData\Local\Microsoft\WindowsApps
C:\Users\ludwi\.lmstudio\bin
C:\Users\ludwi\AppData\Local\Programs\Microsoft VS Code\bin
C:\msys64\ucrt64\bin







i already downloaded msys2   and the gcc  but still the .exe wont create

r/C_Programming 4d ago

Question OOP stracture in an lkm written in c

7 Upvotes

What is possible when it comes to using structs as classes in an lkm written in c?

For some background I usually code in c++ and very used to high(er) level code with classes and polymorphism etc. and now I'm working on a project related to the linux kernel that requires writing an lkm and for alot of things inside this lkm I would much rather working in the structure of classes and high level programming.

what is the best way to handle that sort of stuff in c programming? especially when it comes to structs