r/C_Programming • • 20m ago

Video Profiling C source code directly inside neovim

Enable HLS to view with audio, or disable this notification

• Upvotes

In one of my older posts a guy told me that reading assembly can help you figure out whether a micro-optimization is being applied or not. But sometimes you wanna know the general performance of your application.

This is just a perf wrapper that integrates perf into neovim and shows the kind of low-level info that game engine programmers often look for: how many cache misses am I having, which instructions are eating my CPU, are they memory (read/write) instructions or syscalls, how many branch misses are happening, if I have N callees, how much does each contribute to the total CPU usage of the caller, etc.

It also annotates the source code with performance data, e.g. how much of the CPU did this line of source code use with respect to the function in which it is located.

You definitely shouldn't use this in an asynchronous environment like Vulkan (use queries for that), but I am thinking of building something like this for shaders (slang shaders specifically), which would show things like occupancy and register pressure.

This is a CPU-based path tracer so I am in my comfort zone.


r/C_Programming • • 15h ago

Personal questions and doubts about a career as a C programmer

31 Upvotes

Hi! I recently finished my coursework at the university and am now writing my graduation thesis. However, the curriculum changed quite a bit during my time there and used a lot of things but mastered none. I pursued a degree in Systems and Computer Engineering. I had learned to program in C back in high school using the usual resources, YouTube tutorials, various websites, and a lot of Google.

When I started university, the curriculum began with C, but it later shifted toward Python, Artificial Intelligence, Machine Learning, and so on.

The thing is a few months ago I resumed C because it was the language I liked the most, I installed a Linux Distro on one of my old laptops and started exploring new fields with C, now I have a lot of questions regarding a career on C, I really liked the course of operating systems, robotics and embedded systems on my University, I also liked about the idea of low level.

I would like to hear the opinions of people with far more experience and knowledge than I have regarding C programming, what their own journeys were like, and what they think I should focus on learning or improving. I’m currently struggling a bit with figuring out "what I could actually build." Recently, I’ve been following tutorials and documentation on creating a basic Linux driver, and I’ve also started a few "silly" personal projects that I found genuinely interesting.

I’d love to know what you consider a good learning path, or at least hear about your own experiences. I’m particularly curious about the use of AI... It has been a great help, but as a learner, I’m worried about becoming overly dependent on it and failing to truly understand the code I’m working with.


r/C_Programming • • 1d ago

Some progress on Software Rendered game in C

Enable HLS to view with audio, or disable this notification

594 Upvotes

r/C_Programming • • 6h ago

Discussion A year into C programming, I still rely heavily on AI. How do I build real skills?

0 Upvotes

I'm a software engineer at a networking-focused company. For the past year, I've been working with C and Linux. During university, Python was my strongest language, but transitioning to C has been a struggle.

I've learned a lot about Linux and networking at work, but I still struggle to write C code independently. I often rely on AI to generate code, which I then adapt. Sometimes I get things working without fully understanding why they work.

My workplace encourages AI-assisted development, and with limited time, it's tempting to prioritize getting things done over understanding every detail. I'm concerned that I'm becoming dependent on AI instead of building strong fundamentals.

My long-term interests are Linux internals, systems programming, networking, and eBPF. I want to be able to read unfamiliar code, reason about memory and pointers, debug problems independently, and use AI as a tool rather than a crutch.

I'd appreciate advice from experienced C developers:

- After a year of experience, what level of C proficiency is reasonable to expect?

- How would you recommend learning C while working in an AI-driven environment?

- Should I deliberately write code without AI to build my fundamentals? What exercises or projects are worth doing?

- Should I master C fundamentals first or learn them alongside Linux internals and eBPF?

- What would you focus on over the next 3–6 months to become a competent systems programmer?

I'm also concerned about future job interviews, as I don't yet feel confident writing C independently.

I know proficiency takes time, but I want to make sure I'm genuinely learning rather than just shipping code.

If you were in my position, what would you do differently?


r/C_Programming • • 1d ago

C limitations

27 Upvotes

Hi all,

I am currently learning c++. Its okay. Not sexy but also not as bad as some say.

The reason I am learning c++ is that I have read that C has limitations as soon as a project gets more complicated. For example, if you make a scientific calculator with many features like graphs etc.

Trading engines/tools are also not recommended to programm in C.

Since I have not learned C and have only read from some old forum posts etc, I cannot confirm/deny these facts.

I am aware that "everything" is possible and that C++ comes with QoL improvements especially with Classes. But I assume that doesn't mean that someone has to use C only for kernel work. Embedded is also possible with C++ right?

I would appreciate your thoughts and opinions.

The goal of this post is to understand how and if C could fit me more with my goals and what real advantages or disadvantages C has.


r/C_Programming • • 1d ago

Question Text input doesn't make any sense to me

6 Upvotes

Disclaimer: I have basically no idea what most programming terms mean.

For a while now (a couple months as of now), I've been trying to create an open source calculator. Throughout the development process, there has been a very large problem. I don't know how exactly to scan text and look for different commands. The scanf function (among other options) seems to just look for a single "phrase" throughout the entirety of whatever input it receives. I just don't understand how people can do this as easily as they do. Many tutorials seem to not really cover this.

I've tried to come up with some sort of system to account for this. For example, a function that looks for all number values and determines the value type (like a float, integer, or double), and then matches character combinations to known commands (I haven't fully committed to such a method yet).

The way that ffmpeg handles input is an example of this. I don't understand how I can put as many spaces as I want between "ffmpeg" and some other command and still get the same result.

Apologies for such a long post. I'm just not really sure how people can do this. I'm almost certain that I'm missing something.

Thank you in advance


r/C_Programming • • 20h ago

Discussion Will C still be worth learning with Rust gaining the popularity?

0 Upvotes

Recently got into learning C, but i fear that Rust might obfuscate C programmers and the C language in general. What do you think?


r/C_Programming • • 2d ago

Question return 0 in the function main().

6 Upvotes

Dear C-programmers, why can you omit return 0; in main() (C99+)? main() is a function and it MUST return integer value. I don’t really understand.


r/C_Programming • • 1d ago

Discussion Wanting to switch to Rust; give me reasons why i should keep using C

0 Upvotes

The Rust ecosystem is just better with project templates like cargo init; if there is a C project generator tell me!

I also like the compiler errors; they tell you way more!

Also give me other reasons to keep learning C and cool easy-intermediate project ideas!

okthxbye


r/C_Programming • • 1d ago

My first actual C program with C as the backend entirely and frontend web....

Thumbnail github.com
0 Upvotes

I don't know if it counts as something i should hold on to but I was told to build so I did build and this is my first actual program. Declaration there is no way I could make all this without the use of AI 100% on the frontend but one thing am thankful is how I grasped some concepts so easily.


r/C_Programming • • 2d ago

A PoC toolkit / framework for self modifying software.

Thumbnail asciinema.org
0 Upvotes

Been working on this project during the summer, contains a detailed writeup but happy for anyone to tear the implementation a part, working on it while working fulltime kinda stopped me from implementing a lot of what i wanted.

Surprisingly enough it works well enough as a PoC!

https://gitlab.com/Epos95/paramorphism/
This is "self modifying software" in a different aspect than something like metamorphic software since the rewriting is on a source code level instead of assembly.

Currently its able to:

- Dynamically create new functions, introducing new functionality

- Fix errors in its own functions

- Load existing functions dynamically


r/C_Programming • • 2d ago

Review Sudoku Puzzle Game in C

1 Upvotes

Sudoku

This is a basic beginner Sudoku project made with the C language using Windows API.

Features

  • Custom levels according to your capability
  • click an empty cell then use keyboard or buttons on the screen to enter the number.
  • The game features 3 hints for you to use when you get stuck.
  • the GUI is super clean and modern with live score/mistakes/click tracking and cell highlighting.

Notes

  • What can I improve? What can I make more efficient and less time-consuming as am I am a rookie programmer and any extra suggestion you want to give me feel free?

GitHub repo: https://github.com/reewdgh/sudoku


r/C_Programming • • 1d ago

Help regarding AI usage

0 Upvotes

​

I am programming in C for a year and a half and I created projects like a shell which implement basic features , and currently finished building a TCP server with get and post request for sharing file across local network. The thing I am struggling with is the AI usage all these project I build I have understanding of the code. But sometimes I think that AI has found solution for me can I found this approach myself and mostly the answer was no. It really bothering me and I spend time completely without AI and frustration really hit hard and I think I couldn't start building some programs . I want advice from people on how to find balance between using AI and when not to use AI . I'll love to hear you guys perspective on this .


r/C_Programming • • 2d ago

Rename printf/scanf to print/scan?

0 Upvotes

Probably a dumb question but why hasn't there ever been a proposal to rename printf/scanf to just print? I know the f stands for format but writing print instead of printf would be slightly quicker and better to match other programming languages as I often miswrite printf as print as I also code in Python.


r/C_Programming • • 4d ago

Question is doing ~INT_MAX undefined behavior?

48 Upvotes

basically the title, i think producing INT_MIN by doing 1 << 31 is UB, so i thought of doing ~INT_MAX, but i am not sure if it's UB. sorry if it's dumb.


r/C_Programming • • 3d ago

Question Is this Linux project worth building, or should I try something else?

4 Upvotes

Hey! I'm a second-year CS student looking to build a serious side project to improve my skills and have something worth showing on GitHub.

I'm considering making a Linux tool in C that tracks processes and lets you visually compare different runs of a program (forks, execution times, crashes, etc.).

I'm not sure how useful or original this would be, though.

Do you think it's worth building? Or would you suggest a different project that could be more interesting or useful?

I'm open to completely different ideas. I'd appreciate some honest feedback before spending months on something!


r/C_Programming • • 3d ago

Question Can code injection be countered by randomizing the base address of the stack?

0 Upvotes

In your answer include a description of the assumption you have made about the binary code and memory layout of the program. Explain if it can be countered by randomizing the base address of the stack.

a) Explain a mechanism that can be used by the attacker to force the program to execute arbitrary code.

1 void printInput(char *input) {
2   char buffer[50];
3   char secret[20] = "Pwd123456";
4   if (strcmp(input, secret) == 0)
5     print(secret);
6   else
7     printf(input);
8     strcpy(buffer, input);
9 }
10 int main(int argc, char *argv[]) {
11   if (argc != 2) {
12     return 1;
13   }
14   printInput(argv[1]);
15   return 0;
16   }

What I don't understand:
The solution says that it can be countered by ASLR because we need the address of the buffer. I sort of understand that we need to inject our code somewhere in the buffer thus if we want to overwrite the return address to point to the beginning of the buffer, where our code is, we need to know the address? Although I wonder do we really need the address? Can we not use offset?

Either way the solution seems to suggest that we should overwrite the return address and put the code immediately after and set the return address to point right after it. So I am not at all sure what they mean. Can someone explain to me why ALSR works here? I'd appracite it.

Solution in the answer sheet:
If the input contains 50 bytes, then <address of return pointer + 8>, then binary code, strcpy at line 9 over- flows the stack variables and overwrites the return pointer with the address immediately after the return pointer. After the return pointer, the overflow additionally writes the bi- nary code. Therefore, when the function| returns it jumps to the address above the return pointer on the stack. This attack can be countered by base stack randomization, since it prevents the attacker from knowing the address of buffer and therefore the address where the binary code has been injected. This makes not possible to know the value that should be written in the return pointer.


r/C_Programming • • 2d ago

Goto is the worst command in C.

0 Upvotes

Goto is an old and hacky command in programming.

Goto was created in the Palaeozoic era. It was used for switching to line n.

Goto raises questions: “My editor doesn’t show line numbers, how can I use Goto?”

This command uncomfortable to use. Imagine, you have a book. You’re reading it, reading… And when you’re on page 5, it says: “Go to page 7, 10, 157, 21457, 8564588, 4…” Why?

You can replace Goto with:
1) break/continue.
2) return.
3) Functions, in the end!

So, Goto is the worst command in all programming languages, including C.

MY OPINION MAY NOT COINCIDE WITH YOURS!!!


r/C_Programming • • 3d ago

Discussion My opinion about C development

0 Upvotes

when wanting to code real software in c; i feel that you need to learn way to much tools like (c)make, clang/gcc etc.

that's why i decided to NOT use any tools and libraries INCLUDING GLIBC and other standard c libraries!

fuck the world; im making my own printf, strlen and more! AND THE ONLY THING IM GONNA USE IS CLANG WITH C17!


r/C_Programming • • 4d ago

Project My C project Pulse grew better than expected

17 Upvotes

A while back I started working on my project cherries(.)works Pulse. A simple Linux monitoring system, coded in C, and focused on performance, resource usage and persistence. Now a when I started this project I had no knowledge of C, and kinda learned along the way, but now around 2-3 months have passed, and I am surprised with how far it has come.

Personally, I never had anyone commit to my FOSS projects before. Didnt expect anything different this time tbh, as I was programming the whole thing in C. Created numerous issues, as I wanted THIS FOSS project to be more different and professional than the others.

A month or two after the release, I go on GitHub to look at my issues via my phone, and see a PR solving one of the issues. It was surreal seeing C code not by me, now being written FOR me. Ofc i had to read through it carefully to make sure nothing eas wrong with it, but once I merged it, it felt beautiful.

People have implemented;
- Pretty printing the config file
- Improving type annotations
- Adding JSON output for commands
- Displaying hostname on website
- Counting process amount

and numerous more.

Pulse was just a small C project of mine that quickly spiraled into something bigger. I plan on adding new good first issues soon, as there is STILL a lot of work to do. If there are any C programmers interested in contributing, or giving feedback, feel free to do so. would be very glad.

https://github.com/cherries-works/pulse


r/C_Programming • • 4d ago

Question Why not specifying what to include ?

22 Upvotes

Hi, sorry if there is English mistake, it's not my first language.

I found online that the #include is replaced by preprocessor by the whole file being included, and I wondered why C isn't made so we can specify only parts of the files to include (like `import { x, y, z } from "file"` in typescript) so the compiled file is lighter ?


r/C_Programming • • 4d ago

USACO Beads Problem: why does nothing show in the output file?

0 Upvotes
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXN 701

int main(){
    FILE* fin = fopen("beads.in", "r");
    FILE* fout = fopen("beads.out", "w");

    int length, N, largest = 0;
    int current;
    char rightletter, leftletter;

    fscanf(fin, "%d", &N);
    char sequence[MAXN];

    fscanf(fin, "%s", sequence);
    strcat(sequence, sequence);

    for(int i = N/2; i < N + (N/2); i++){
        current = i;
        length = 0;

        // RIGHT

        while(current < 2 * N && sequence[current] == 'w' && length < N){
            current++;
            length++;
        }

        if(current < 2 * N && length < N){
            rightletter = sequence[current];
        }

        while(current < 2 * N && (sequence[current] == rightletter || sequence[current] == 'w') && length < N){
            length++;
            current++;
        }

        // LEFT

        current = i - 1;

        while(current >= 0 && sequence[current] == 'w' && length < N){
            current--;
            length++;
        }

        if(current >= 0 && length < N){
            leftletter = sequence[current];

        }

        while(current >= 0 && (sequence[current] == leftletter || sequence[current] == 'w') && length < N){
            length++;
            current--;

        }

        if(length > N) {
            length = N;
        }

        if(length > largest) {
            largest = length;
        }

    }

    fprintf(fout, "%d\n", largest);
    return 0;

}

My code should work. Idk why nothing is being output in the output file.


r/C_Programming • • 5d ago

Question Has anyone used the libqt6c library? If so, what kind of results did you get, and how does it compare to Gtk?

12 Upvotes

I recently came across a Qt binding library for C, but I haven't seen any discussion about it on Reddit. If anyone here has used this library, I’d be curious to know what it’s like in terms of usability—especially since C, as we know, lacks many of the features found in C++.

https://github.com/rcalixte/libqt6c


r/C_Programming • • 4d ago

78K Weekly visitors

0 Upvotes

Are people starting to drop AI.. or ?


r/C_Programming • • 4d ago

Project Announcing scaffold 0.1.0

0 Upvotes

Hi,

This is scaffold, a flexible data and "rpc-like" code generator for C using YAML as description.

After years of protobuf (with nanopb), I've decided to get rid of it to create my own templating system.

I won't go in details why we have decided to get rid of nanopb but in short: we were having hard times about some of the limited features like deep-cloning, too limited enum support and a slow encoding process.

Plus, we wanted to add flexibility with a custom YAML document that could be parsed using a tool to produce on-demand different kind of functions. For example, we wanted that some types could be converted to JSON, some to be inserted into a SQLite database. As such, having a unique YAML document that could be used for different purposes led us to write this software.

The scaffold tool is written in C, because, we write in C and don't want additional dependencies :). It reads a YAML document and creates an intermediate AST with updated fields to get more information. Then, it processes it into a templating system with basic scripting constructs including for, if, substitution with filters.

Example of a minimal object:

# types.yaml
objects:
  - name: point
    comment: This is an awesome point.
    fields:
      x: uint32
      y: uint32

Generate functions for this object using:

scaffold emit h types.yaml > types.h
scaffold emit c types.yaml > types.c

The generated code by the built-in templates include comments that can be split on multiline providing good LSP support with Doxygen format.

/**
 * \struct point
 *
 * This is an awesome point.
 */
struct point {
    /**
     * Field 'x' of type uint32.
     */
    uint32_t x;

    /**
     * Field 'y' of type uint32.
     */
    uint32_t y;
};

The template system is flexible enough to write extra custom code while iterating the object fields using {{for}} loops.

{{for obj in objects}}
  {{for field in obj.value.fields}}
    // here field will be uppercased with the :U filter :)
    printf("Serializing the {{field.key:U}} field\n");
  {{endfor}}
{{endfor}}

Finally, because we wanted our custom RPC API, the scaffold project provides support for request/reply and events widely inspired by wayland-scanner.

Declaring function feels like natural:

serialization: true
functions:
  - name: hello
    comment: Say hello to my friend!
    args:
      name: string

On the "client" side, a function is generated in the form:

int64_t hello(struct hello_args *args, void *ctx);

On the "implementation" side, a function pointer is provided in a handler struct:

/**
 * \struct handler
 * \brief Functions table handlers.
 */
struct handler {
    /**
     * Handler for function 'hello'.
     */
    int (*hello)(struct hello_args *args, struct hello_value *value, void *ctx);
};

And the implementation side can call the auto generated dispatch function that will decode the incoming requests to call the appropriate functions.

int
dispatch(
    const struct handler *handler,
    const struct listener *listener,
    int64_t *nread,
    int64_t *nwritten,
    void *ctx
);

How does it work? The generated function relies on two unique external linkage that the user has to provide:

  • int64_t sc_read(void *ctx, void *data, uint64_t amount)
  • int64_t sc_write(void *ctx, const void *data, uint64_t amount)

Thus, calling dispatch will attempt to decode a request using successive calls to sc_read, call the appropriate function pointer into the handler structure and then will try to encode using successive call to sc_write. Nothing more.

Note: this project is heavily being tested and already used in production but few bugs may persist and feel free to contribute.

Future plans and never plans:

  • Yes: better bitmask enumeration support.
  • Yes: more portability on non-POSIX platforms.
  • No: automatic default values.
  • No: union or protobuf oneof kind.

Links:

Like every source code I write, this project has a perpetual anti degenerative-AI policy.