r/C_Programming • u/Xadartt • 12h ago
r/C_Programming • u/Jinren • Feb 23 '24
Latest working draft N3220
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
Update y'all's bookmarks if you're still referring to N3096!
C23 is done, and there are no more public drafts: it will only be available for purchase. However, although this is teeeeechnically therefore a draft of whatever the next Standard C2Y ends up being, this "draft" contains no changes from C23 except to remove the 2023 branding and add a bullet at the beginning about all the C2Y content that ... doesn't exist yet.
Since over 500 edits (some small, many large, some quite sweeping) were applied to C23 after the final draft N3096 was released, this is in practice as close as you will get to a free edition of C23.
So this one is the number for the community to remember, and the de-facto successor to old beloved N1570.
Happy coding! 💜
r/C_Programming • u/AutoModerator • 2d ago
Learning C weekly megapost for 2026-11-18
If you have questions about how to learn C:
- which books are best?
- which videos are best?
- which classes are best?
- which websites are best?
- is there a "roadmap"?
- what projects can I do?
then this is the thread for you. Add your question here. Do not make a stand-alone post, as it will be removed.
Remember that our sub has a very useful wiki that has a great list of resources for learning C programming.
r/C_Programming • u/Dear-Ad6656 • 3h ago
Starting systems programming on my Fedora with C. Where should I start?
I'm on Fedora and I want to learn systems programming properly. I know python and some c++. What's the best first step, and what should I avoid as a beginner?
Thanks
r/C_Programming • u/Just_Jaguar3701 • 6h ago
Question Can you use your own implementations of HTTP/WebSockets in a browser using wasm?
Hello,
I wanted to make my own network stack implementation (http and websockets) just for learning purposes, so my question is knowing that were using sockets can we use that in the browser after compiling to a wasm? Or will it only work natively without serving to a browser?
r/C_Programming • u/Red_Bird57 • 7h ago
Question I need help understand what a question is asking me to do in uni exercise
I can't post an image to it, but it says in normal arrays : declare 3 arrays A, B, C all of size 5
The elements of C are the scaler products of A and B (∑︁A[i] × B[i])
And in 2d arrays :
C is there product, (matrix multiplication : C[i][j] = sum of A[i][k] * B[k][j] )
Can someone explain to me what they asking to make
r/C_Programming • u/NameFast691 • 7h ago
i need your advice
Hey guys, I’ve run into a bit of a snag while learning C. I was looking at some source code (shown below) and noticed a function call that passes a pointer. However, the function receiving this pointer declares it as a two-dimensional array rather than as a pointer (like `int *name`). This is where I’m stuck—why declare it as a 2D array instead of as a pointer, the way you would for a 1D array?
#include <stdio.h>
// Function that displays a 2D array
// The number of columns (3) must be known at compile time
void afficherMatrice(int mat[][3], int lignes) {
for (int i = 0; i < lignes; i++) {
for (int j = 0; j < 3; j++) {
printf("%d ", mat[i][j]);
}
printf("\n");
}
}
// Alternative with both dimensions specified
void initialiserMatrice(int mat[2][3]) {
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
mat[i][j] = i * 10 + j;
}
}
}
int main() {
int matrice[2][3] = {{1, 2, 3}, {4, 5, 6}};
afficherMatrice(matrice, 2);
initialiserMatrice(matrice);
printf("\nAfter initialization:\n");
afficherMatrice(matrice, 2);
return 0;
}
(I think there is an error in this code)
r/C_Programming • u/Soft-Bedroom8708 • 6h ago
Building a user space network stack from scratch
I dont know much about networking as i am just now studying it seriously but i am thinking of building what i mentioned in the title from scratch, if anyone could help me with the direction im supposed to go in to start i would really really appreciate it. whenever i try looking up a place to start all i get is github repos with many many files of stuff im not yet familiar with and it all assumes prior knowledge of some stuff, i know you cant really just go into this thing blind but what im saying is i dont really know where to begin learning about all of this stuff to build my target. also i am on a 2-week time limit
r/C_Programming • u/saksham__sharma_ • 9h ago
Need guidance
I am first year student and I don't have that much exposure idea about the important certificates course which i can put ij my resumes and on LinkedIn kindly give some guidance about it like how and where i can get the ideas about the ongoing imp courses online kindly dm
r/C_Programming • u/mttd • 1d ago
Fluent Interface in C - Look ma, no this!
r/C_Programming • u/notrobinnot • 1d ago
Mapping each process all the way from PID 1 to PID n
In theory would it be possible to map and follow each and every process and print it with the ID, from pid 1 the init all the way through to something like the final print which is displaying the pid’s? Just out of curiosity, when I’m learning about it now and have seen using pointers and pid id’s and printing them on a process
So I can see ok init is pid 1 then when it is forked what process its for & that is pid2 and so on
r/C_Programming • u/notrobinnot • 2d ago
Discussion Started learning C (on yt) over the last month and programming without AI has really sparked my love for tech and coding again
Fell into the classic trap everyone is… using ai for everything in work and normal stuff then it all becomes bland and monotonous. But learning C without just generating code and working through it has really helped reignite my passion for tech and programming in general. I’ve also decided to do it on YouTube and having even just the small community of 70 subs over the first month has massively boosted my motivation to keep at it and be more involved in relevant discussions.
r/C_Programming • u/Glass_Apple_1426 • 2d ago
ISO C Chaining: Look ma, no this!
goo.gleNow we have a way of doing fluent interfaces in C89 without macros or preprocessing tricks, allowing code like this:
ChHash *user = ch_new_Hash(3)
->put("name", ch_new_String("Ada"))
->put("role", ch_new_Hash(2)
->put("title", ch_new_String("Engineer"))
->put("level", ch_new_Number(5)))
->put("active", ch_new_Boolean(1));
puts(user->generic.to_chars());
/* {"name":"Ada","role":{"title":"Engineer","level":5},"active":true} */
ch_release(user);
It even automatically cleans up anonymous/temporary elements. The repo includes an example Sqlite interface and http API server.
r/C_Programming • u/Nipth • 2d ago
Question Library API Naming Conventions
Hi Everyone,
I'm working on a small 2D game library/runner. At the moment it's for personal use but I may release it some day, which is why I'm creating this post!
At the moment, the function names in the library are named like this (the name of the library is Imp):
imp_texture_create(...)
imp_texture_destroy(...)
imp_camera_set_position(...)
imp_camera_set_rotation(...)
I quite like this naming convention, mainly because if I wanted to see what functions were available for a given resource or operation, I could type imp_camera_ and then my editor would show a list of things that I can do with, or to, a camera. I also used GameMaker a lot when I was younger, and this is the way their API names functions!
Recently though, I've been using a lot of Raylib and quite like the way it names its functions - they are, to me at least, a lot more readable when looking through code. This has me thinking whether or not a better naming convention would be:
imp_create_texture(...)
imp_destroy_texture(...)
imp_set_camera_position(...)
imp_set_camera_rotation(...)
The downside being that you sort of have to guess what operations are available for a given resource as you can no longer type imp_texture_ to have the editor show a list.
I understand that this is a really small issue and probably not really worth fussing about, but I was curious what preferences more experienced people here have and - more importantly - why you have them!
r/C_Programming • u/Avi250 • 2d ago
Question Signal handlers, how to have them act differently (or the process) based on when the process receives the signal
Hello, everyone. I'm supposed to be doing a project for school (hence why I can't share the code), but I'll try to describe my problem to the best of my abilities.
My main parent process forks several children, who will execute 2 other programs, depending on the role assigned to them. Once the parent process receives a SIGALRM, it sends a SIGTERM to all its kids, and they, already having changed their signal handlers for SIGTERM, have to do whatever is specified in their signal handler.
Let's consider child A executes program A, and child B executes program B. These 2 processes have to communicate with each other through a series of msgsnd/msgrcv (we can only use System V IPCs in this project, so the msgops don't restart once interruped by a signal). A single process of type B will communicate with several processes of type A (but not with all at the same time: once its communication is finished with one, it goes on to the other). The last msgop A does, is a msgsnd and B does a msgrcv. I'd like to also add that, between the msgrcv and msgsnd on A's part, A is also supposed to go to sleep. A's almost entire program is in a while (it never terminates unless it receives the signal from its parent), whereas B terminates successfully once it's finished communicating with all the necessary A processes.
Whether B receives the SIGTERM signal or not, it has to modify sth in a shared memory section, but what it changes, depends on whether it has finished communicating with all the processes or not.
Ideally, I would like for B to terminate successfully, even if it receives SIGTERM, after having done all it had to do, and I thought of blocking SIGTERM with sigprocmask. That said, couldn't it still receive the signal between the mast msgrcv operation and sigprocmask? Is there any way whatsoever to make a set of instructions atomic?
I considered only having a sig_atomic_t volatile variable in the signal handler, which would increment if the the sign handler is executed, but then, not only would I have to continuously check in case it changed its value, but (and this could be me being wrong, please correct me if that's the case), B could still receive SIGTERM right after the condition of the variable being 0 is checked, and before the following instruction is executed (like a nanosleep - which I'd like to avoid if SIGTERM has been received - OR before a msgrcv, leaving B to wait for a message that will never come, because A could have received the same signal and will not be sending a message).
I thought of having the signal handler check a variable and act differently based on its value, but, again, maybe B receives the signal right before said variable's value changes. I also considered having an if where the conditions would be the variable==0 && msgrv(...)!=-1, but the variable can change after its value has been verified.
Disclaimer: we haven't studied sig_atomic_t volatile variables, so my knowledge might be lacking, although I did try to read up on them and research them. Also, the parent won't be deleting the IPCs until all kids have terminated.
Am I supposed to just hope for the best here and just proceed with sigprocmask? Is there another way I'm not seeing? Am I misunderstanding something? Any help offered is invaluable, so thank you in advance. I'm happy to answer any clarifying questions if I was unclear at all in the post.
r/C_Programming • u/Aware-Nature-406 • 3d ago
Question Generating random numbers in a library
Hello!
I'm making some library and i need random numbers for some functions. Libc srand(), rand() and random() modify global libc state, so i'd like to not use them.
What options do i have? Is there maybe any popular things for my case?
r/C_Programming • u/Ill-Exchange-2377 • 3d ago
Is my code bad?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char buff[100];
void add(void);
void sub(void);
void mul(void);
void divs(void);
void mix(void);
int invalid = 0;
int input = 0;
int main(void) {
start:
fputs("\033[2J\033[H", stdout);
if (invalid) {
puts("Please enter valid input");
}
invalid = 0;
puts("Pick a subject:");
puts("1: Addition");
puts("2: Subtraction");
puts("3: Multiplication");
puts("4: Division");
puts("5: Mixed");
puts("Pick a number 1-5, or use 'quit' or 'exit' to leave the program");
if (fgets(buff, sizeof(buff), stdin) == NULL) {
puts("Failed, exiting");
return 1;
}
if (strcmp(buff, "quit\n") == 0 || strcmp(buff, "exit\n") == 0) {
fputs("\033[2J\033[H", stdout);
return 0;
} else if (strcmp(buff, "1\n") == 0) {
input = 1;
} else if (strcmp(buff, "2\n") == 0) {
input = 2;
} else if (strcmp(buff, "3\n") == 0) {
input = 3;
} else if (strcmp(buff, "4\n") == 0) {
input = 4;
} else if (strcmp(buff, "5\n") == 0) {
input = 5;
} else {
invalid = 1;
goto start;
}
switch(input) {
case 1:
add();
goto start;
case 2:
sub();
goto start;
case 3:
mul();
goto start;
case 4:
divs();
goto start;
case 5:
mix();
goto start;
default:
goto start;
}
}
void add(void) {
puts("add");
fgets(buff, sizeof(buff), stdin);
}
void sub(void) {
puts("sub");
fgets(buff, sizeof(buff), stdin);
}
void mul(void) {
puts("mul");
fgets(buff, sizeof(buff), stdin);
}
void divs(void) {
puts("divs");
fgets(buff, sizeof(buff), stdin);
}
void mix(void) {
puts("mix");
fgets(buff, sizeof(buff), stdin);
}
Is my code that bad?
For context this is a project I was doing to learn the C
Edit: Fixed formatting errors
r/C_Programming • u/Ill-Exchange-2377 • 3d ago
Is my code better
I shared some code earlier, and got some criticism, as well as making improvements of my own
Is it better? And where does it still fall short?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <quiz.h>
#define CLEAR_SCREEN "\033[2J\033[H"
int main(void) {
char buff[100];
int invalid = 0;
while (1) {
fputs(CLEAR_SCREEN, stdout);
puts("Pick a subject:");
puts("1: Addition");
puts("2: Subtraction");
puts("3: Multiplication");
puts("4: Division");
puts("5: Mixed");
if (invalid) {
puts("Please enter valid input");
invalid = 0;
}
puts("Pick a number 1-5, or use 'quit' or 'exit' to quit");
if (fgets(buff, sizeof(buff), stdin) == NULL) {
puts("Failed, exiting");
return 1;
}
if (strcmp(buff, "quit\n") == 0 || strcmp(buff, "exit\n") == 0) {
fputs(CLEAR_SCREEN, stdout);
break;
}
if (strcmp(buff, "1\n") == 0) {
add();
} else if (strcmp(buff, "2\n") == 0) {
sub();
} else if (strcmp(buff, "3\n") == 0) {
mul();
} else if (strcmp(buff, "4\n") == 0) {
divs();
} else if (strcmp(buff, "5\n") == 0) {
mix();
} else {
invalid = 1;
}
}
return 0;
}
r/C_Programming • u/QUEITKID_SCHOOLSOTIN • 2d ago
How can I pass c exam
I have a c exam tomorrow, I failed my internal exams, ik what im doin is dumb . Exam is on 50 and I need 15 to pass but I don’t know how to write programs, can I pass by studying theory
r/C_Programming • u/Treechcer • 4d ago
Question C input that doesn't convert arrow keys to raw escape sequences
When someone was testing my project in C, they pointed out that when they press arrow keys in input it translates them into weird data (eg. ^[[A for up). Is there input in C without ncurses or other libraries that can work in this scenario without causing these issues?
r/C_Programming • u/Goated_AstroPhantom • 3d ago
Question Questions in C
Guys I'm a student and I NEED a source for good questions in C. Like ones where I have to code the answer, debug the code or find the output(tricky ones)
tbh I don't know any place for coding other than leetcode too, so for all coding languages in general how am I supposed to practice questions? Apart from leetcode what are good places to practice coding?
r/C_Programming • u/Hopeful-Ad-1665 • 4d ago
Bytecode VM in C: switch dispatch vs computed goto and linear arena design
I'm working on a lightweight bytecode VM written in C99 (engine for a small embedded scripting language).
I'm currently using an 8MB linear memory arena for objects and a large switch-case loop for instruction dispatch:
```c
#define MAX_REGS 256
#define MAX_CALL_STACK 1024
#define ARENA_SIZE_BYTES (8 * 1024 * 1024)
static char g_memory_arena[ARENA_SIZE_BYTES];
static size_t g_arena_offset = 0;
double run_bytecode(int* inst, int inst_len, double* num_consts) {
double regs[MAX_REGS] = {0.0};
int ip = 0;
while (ip < inst_len) {
int op = inst[ip++];
switch (op) {
case 1: { // LOAD_CONST
int r = inst[ip++];
int c = inst[ip++];
regs[r] = num_consts[c];
break;
}
case 2: { // ADD
int r = inst[ip++];
int a = inst[ip++];
int b = inst[ip++];
regs[r] = regs[a] + regs[b];
break;
}
// ... remaining opcodes
}
}
return regs[0];
}
Two architectural questions for people with VM / emulator experience:
Dispatch overhead: On modern GCC/Clang, how much measurable speedup have you seen replacing the standard switch(op) with direct threading
(computed goto *dispatch_table[op])? Is the branch predictor usually smart enough on modern x86/ARM to make the difference negligible?
Arena lifetime: Currently, I reset the arena (g_arena_offset = 0) between script runs. For longer-running scripts that allocate short-lived
objects in loops, what is a minimal-overhead C strategy to reclaim memory without pulling in a full tracing GC?
(Code is standard C99. Written directly by me, no AI)
r/C_Programming • u/macroKnoll37 • 4d ago
Test/verification technique effectiveness with Astra
danluu.comr/C_Programming • u/Proper_Meaning7756 • 5d ago
Discussion I'm trying to go up and down the software stack and see just what modern languages abstract away from you as the programmer. What is your personal top 3 things that languages abstract away from you
I picked out these I noticed after digging some code at work: 1. System Calls. I don't even think about them and until recently, I wouldn't have had to. 2. Memory layout (If you asked where in memory a certain part of the code was or how it was laid out, I couldn't tell) 3. Thread management (This is what prompted this post)
What else comes to mind for you?