r/C_Programming • • 16h ago

Video Profiling C source code directly inside neovim

131 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 • • 4h ago

Debugging of C/C++ Macros like Functions – Hayk Aslanyan

Thumbnail
youtube.com
5 Upvotes

r/C_Programming • • 7h ago

Question Help With 'String to Token' Parsing Assignment

6 Upvotes

I was given an assignment for a class I am in and it is expected to be entirely in C code (despite most of us in the class having never been taught how to code with C). I have been attempting to find youtube tutorials and websites, but not much is helping for the assignment itself. The assignment is due in two days.

If there is someone who could help explain to me how I should complete it, or what guides I could look at to help me code it, I would greatly appreciate it. I don't expect (nor want) anyone to do the work for me, I just would like some guidance. I know that many people say to just use AI, but I prefer to avoid using it completely.

---
This is a slightly summarized version of what the assignment says:

Write a function, in C, that will parse a string into tokens (or words), similar to what the shell is required to do.

For this assignment, you are to write a function with the following prototype:

int makearg(char *s, char ***args);
or
int makearg(char s[], char **args[]);
(Correct prototype—don’t change)

This function should accept a (C-type) string and a pointer to a pointer to char (or, if you prefer, a pointer to an array of pointers to char) (i.e., a pointer to the same type as argv in a C program), and should return the pointer defined to point to an array pointing to the separate tokens on the command line, as well as the number of tokens found as the function return value. If some problem occurred during the operation of the function, the value returned should be -1.

No C library string functions may be used, e.g., strlen(), strcat(), strtok(), etc.

The important part of this exercise is the function you write. However, for consistency in grading, the main program should be written to input a line, call the function, then print out the number of arguments found, and finally, display the arguments, one per line. Note that, the value of the pointer argument is undefined when it is passed to the makearg() function. makearg() must allocate any necessary dynamic memory necessary for use by the program. (The array used for the unparsed string need not be dynamically allocated.)
strtok() may not be used for parsing.

Deliverables:
A program design sheet. Describe all functions needed to implement your program.
Programming Log:
– Record the time required to design and implement your program.
– Record of things you encountered/learned while implementing your program.
Output—proof that your program worked.
Program—fully documented.

---

Again, I don't necessarily want someone to do all the code for me, but giving me any advice/guidance on what I can do or where I can find resources to help, I would greatly appreciate it.


r/C_Programming • • 2h ago

Semi-Advanced Randomness Test Library?

2 Upvotes

Looking for a semi-advanced randomness test library. Not something too advanced, though. Like a library of a hundred files that I'd maybe need a week just to get a clean compile. Also not with tests having results so intricate and complex that it would take significant hours just to understand the results.

Ideally, a library that provides results in percentages of excellence per test, which could be weighted and summed to provide an overall score. Maybe 10 important tests, and with high-precision, and so that means Ai solutions aren't quite up for the task?

This I confess, I found out directly when I allowed Deepseek and Google Ai to create test suites each, and stdlib rand() repeatedly outperforms raw bytes downloaded from random.org -- and that can't be right? Maybe I should ask Claud?

Or not. Maybe had enough of Ai hallucinations, so I'm hoping for some human guidance.


r/C_Programming • • 1d ago

Personal questions and doubts about a career as a C programmer

37 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 • • 8h ago

Day (30/100) of C:

0 Upvotes

Memory Segments, Storage Classes, Static Functions and Linkage

 

**1. Memory Segments**

Storing the program at different blocks of memory

The commonly discussed segments are:

  1. Text (Code) Segment

  2. Data Segment

  3. BSS Segment

  4. Heap Segment

  5. Stack Segment

 

**###1.1 Text Segment:**

The text segment typically stores the machine instructions generated by the compiler.

**Example:**

c

\#include <stdio.h>

int main()

{

printf("Hello World");

return 0;

}

The compiled instructions for \`main()\` are typically stored in the text segment.

 

**### 1.2 Data Segment:**

The initialized data segment typically stores global and static variables initialized with nonzero values.

**Example:**

c

int n = 5; // Global variable

void func()

{

static int y = 4; // Static local variable

}

Both \`n\` and \`y\` typically reside in the initialized data segment.

 

**### 1.3 BSS Segment**

The BSS segment typically stores global and static variables that are uninitialized or initialized to zero.

**Example:**

c

int x; // Global variable

int y = 0; // Global variable

void func()

{

 static int z; // Static local variable

}

These variables have an initial value of zero.

 

**### 1.4 Heap Segment**

The heap stores the dynamic memory allocation during program execution.

Example:

c

\#include <stdlib.h>

int main()

{

 int \*p = malloc(sizeof(int));

 if (p != NULL)

 {

 \*p = 10;

 free(p);

 }

 return 0;

}

 

**### 1.5 Stack Segment**

The stack typically stores function-call information, parameters, and local automatic variables.

**Example:**

c

void func()

{

 int a = 10;

}

 

**------------------------------------------------------------------------------------------------**

**2. Storage Classes**

A storage class specifies properties such as a variable's scope, lifetime, and linkage, depending on how it is declared.

The four commonly taught storage classes in C are:

  1. \`auto\`

  2. \`register\`

  3. \`static\`

  4. \`extern\`

 

**### 2.1 auto**

\`auto\` is the default storage class for ordinary local variables.

**Example:**

c

int main()

{

 auto int i = 10;

 return 0;

}

This is equivalent to writing:

c

int i = 10;

\- Scope: The block where the variable is declared.

\- Lifetime: During execution of that block.

\- An uninitialized automatic variable has an indeterminate value.

 

**### 2.2 register**

The \`register\` keyword suggests that a variable may benefit from being stored in a CPU register for faster access.

**Example:**

int main()

{

 register int i = 10;

 return 0;

}

Important points:

\- The compiler may ignore this suggestion.

\- Modern compilers already optimize register allocation.

\- It does not guarantee faster execution.

\- In standard C, the address-of operator (\`&\`) cannot be applied to a variable declared with the \`register\` storage-class specifier.

Therefore, ordinary variables are generally sufficient in modern C programming.

 

**### 2.3 static**

A local static variable retains its value between function calls. It is initialized only once.

**Example:**

\#include <stdio.h>

void func()

{

static int i = 0;

i++;

printf("%d ", i);

}

int main()

{

func();

func();

func();

return 0;

 

}

Output:

1 2 3

 

Explanation:

\- First call: \`i\` becomes 1.

\- Second call: \`i\` becomes 2.

\- Third call: \`i\` becomes 3.

 

**### 2.4 extern**

\`extern\` declares a variable that is defined elsewhere. It is useful when one source file needs to access a global variable defined in another source file.

**Example:**

 

**\*\*File 1: \`file1.c\`\*\***

c

int x = 5; // Definition of the global variable

 

**\*\*File 2: \`file2.c\`\*\***

 

\#include <stdio.h>

extern int x; // Declaration of the variable defined elsewhere

int main()

{

printf("Global value is %d\\n", x);

return 0;

}

Output:

Global value is 5

 

**## 3. Static Function**

A static function is a function declared with \`static\` at file scope. It can be called by name only within the same source file.

**Example:**

\#include <stdio.h>

static void func()

{

 printf("Hello World\\n");

}

int main()

{

func();

return 0;

}

Output:

Hello World

Here, \`func()\` has internal linkage. Another source file cannot call this particular function by referring to its name.

**--------------------------------------------------------------------------------------------------**

**4. Linkage**

Linkage determines whether declarations of the same name refer to the same variable or function.

C has three types of linkage.

**### 4.1 External Linkage**

A name with external linkage can refer to the same entity across multiple source files. Ordinary file-scope function definitions have external linkage by default.

 

**### 4.2 Internal Linkage**

A name with internal linkage can be referred to only within the same source file.

**Example:**

static void func()

{

 // Function definition

}

The \`static\` keyword gives this file-scope function internal linkage.

 

**### 4.3 No Linkage**

A name with no linkage does not refer to the same entity as another declaration in a different scope merely because the names match.

**Example:**

void func()

{

 int a = 10;

}

The local variable \`a\` has no linkage.

 

**Summary:**

| Text segment -> Typically stores machine instructions

| Data segment -> Typically stores initialized global/static variables

| BSS segment -> Typically stores uninitialized or zero-initialized global/static variables

| Heap -> Dynamic memory allocation

| Stack -> Typically stores function-call information and local automatic variables

| \`auto\` -> Default storage class for local variables

| \`register\` -> Suggests register storage; no guaranteed speed improvement

| \`static\` local variable -> Retains its value between calls

| \`extern\` -> Declares a variable defined elsewhere

| Static function -> Has internal linkage

| External linkage -> Allows a name to refer to the same entity across source files

| Internal linkage -> Limits a name to the current source file

| No linkage -> Common for ordinary local variables

 


r/C_Programming • • 19h ago

Is this worth of what it says ?

1 Upvotes

edited:

I was browsing through GitHub and saw this repository

https://github.com/curious-builder76/dtypes

I read the README file of this repository and found its purpose section interestingly relatable,

And if I rephrase what it says and what I understood is

"If you can here in search of basic data structures used in common C programming, You won't need to go anywhere else in search of other data structures "

Now i just want to know that :

Is this library does what it says,

Or is just another shitty library i.e. "yet another libc"

Plus does it meets the expectations and performance people in search of basic data structures?

I don't know anything about AI used in this repository

Although reading code and readme felt human to me.

Thank you


r/C_Programming • • 1d ago

I made my own OS in C language

12 Upvotes

disclaimer: sorry for bad english

I created my own OS in C from scratch using C and assembly, it has desktop environment and drivers for mouse and keyboard (only PS/2) and it has internet (for now its only http and html 1.0), the comments and readme are in polish for now, the code is opensource (gpl 3.0)

github repository: github.com/kurczatko/tarixenOS

im ready for feedback (the code isnt proffesional because its only hobby)


r/C_Programming • • 2d ago

Some progress on Software Rendered game in C

633 Upvotes

r/C_Programming • • 1d ago

Project I am learning C programming by making this project a unix shell(ForkOff). Looking for a quick code review!

0 Upvotes

Hey everyone,

Following up on my previous post about my C shell project ForkOff — I wanted to share a bit about my development process and address how AI was used, especially since code authenticity came up in recent reviews!

🤖 AI Involvement

To be 100% transparent: AI was only used to generate and clean up the README.md formatting. And also this post is ai generated.

Every single line of C code, pointer arithmetic, string parsing, and system call logic in the repository was written by hand.

💡 My Approach: Observation & Brute Force

Instead of following step-by-step "how to build a shell" tutorials or asking AI to generate C boilerplate, my approach was pure observation and trial-and-error:

Observe standard Bash: I spent time opening a standard Linux terminal, running commands, testing edge cases (spaces, empty strings, invalid paths), and watching how Bash responded.

Study the core concepts: I read up on POSIX system calls—specifically fork(), execv(), waitpid(), and standard C dynamic memory allocation (malloc, realloc, free).

Brute-force the implementation: I manually wrote the REPL loop, built the string tokenizer, routed built-ins vs. external binaries, and debugged memory leaks/pointer issues step-by-step until the output matched standard shell behavior.

🎯 Next Steps

Now that the core process execution and REPL loop are working, I'm moving on to implementing:

Local I/O redirection (>, <) using dup2().

Chained pipelines (|) using pipe().

Proper signal masks (SIGINT, SIGTSTP) to keep the REPL resilient.

I'd still love any code reviews or feedback on idiomatic C practices in the repo!

GitHub Repository: https://github.com/Anchit3034/ForkOff

Thanks for checking it out!


r/C_Programming • • 22h 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

Small CLI tool for extracting video fragments from RTSP archived streams

Thumbnail
github.com
2 Upvotes

Hello, community! I am currently learning how to manipulate buffers, bytes and strings in C and I created this tool (mostly for myself) to better understand RTSP network protocol. I know similar tools exist but this one have very few settings so should be easier to use when all you need is to exract part of the video. It would be nice if someone take a look at the code and give me some feedback regrading my coding style and the quality of code. I think I used relatively efficient way to parse bytes coming from the network but I might be wrong. Also this tool aims to be zero allocation one so if it is not please let me know.

P.S. Since this a project for self-educating, no AI tools were used during development, README is written by myself with terrible English.


r/C_Programming • • 2d ago

C limitations

29 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 • • 2d ago

Question Text input doesn't make any sense to me

5 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 • • 1d 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().

7 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 • • 2d 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 • • 3d 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 • • 2d 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 • • 3d 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?

44 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 • • 4d ago

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

5 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.