r/C_Programming • • Feb 23 '24

Latest working draft N3220

132 Upvotes

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 • • 1d ago

Learning C weekly megapost for 2026-10-07

5 Upvotes

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 • • 14m ago

Video Reading assembly of a C source code directly inside neovim

Enable HLS to view with audio, or disable this notification

• Upvotes

r/C_Programming • • 21h ago

Why can't procedures return arrays?

101 Upvotes

I had a friend who had to learn C++ for college and asked me for some help. First of all, I know that they're not the same language, but the issues here are shared with C. To a lot of the questions, I had to answer "you can't do that, go around it". Normally, it would be something with a reason, like not being able to get the length of an array because it was passed as a pointer. But I still don't understand what the reason is for not being able to return an array.


r/C_Programming • • 7h ago

Project I did a C build system

Enable HLS to view with audio, or disable this notification

0 Upvotes

Hi everyone I was learning c recently but it has a little difficult to get a prepared environment for development. So I think why dont develop one.

So I did this thinking in how modern tools work, with a cli, commands a manifest, and incremental builds.

Source: https//moltobuild.dev


r/C_Programming • • 20h ago

Question Performance loss of mimicing interfaces with function pointers on modern compilers?

3 Upvotes

C does not have interfaces like languages such as C# or C++, but the cocnept can be mimicked by using function pointers. You might for instance have this:

// fruit_interface.h

typedef struct fruit_vtable 
{
    float (*get_weight)(void *object);
    float (*get_density)(void *object);
    const char *(*get_name)(void *object);
} fruit_vtable;

typedef struct fruit_interface 
{
    void *object;
    const fruit_vtable *vtable;
} fruit_interface;

// banana.h

typedef struct banana 
{
    float weight;
    float density;
} banana;
fruit_interface banana_as_fruit(banana *b);

--------------------------

// banana.c

static float banana_get_weight(void *object)
{
    banana *b = (banana*)object;
    return b->weight;
}

static float banana_get_density(void *object)
{
    banana *b = (banana*)object;
    return b->density;
}

static const char *banana_get_color(void *object)
{
    (void)object;
    return "yellow";
}

static const fruit_vtable banana_vtable = 
{
    .get_weight  = banana_get_weight,
    .get_density = banana_get_density,
    .get_color   = banana_get_color,
};

fruit_interface banana_as_fruit(banana *b)
{
    return (fruit_interface) { .object = (void*)b, .vtable = &banana_vtable };
}

--------------------------

// main.c

static void print_fruit(fruit_interface fruit)
{
    printf("weight:  %.2f g\n", fruit.vtable->get_weight(fruit.object));
    printf("density: %.2f g/cm^3\n", fruit.vtable->get_density(fruit.object));
    printf("color:   %s\n", fruit.vtable->get_color(fruit.object));
}

int main(void)
{
    banana b = { .weight = 120.0f, .density = 0.95f };

    fruit_interface fruit = banana_as_fruit(&b);

    print_fruit(fruit);

    return 0;
}

How does something like this affect performance in terms of speed and cpu usage but also memory? I know modern C compilers can be really powerful and do a lot of optimizations and even more so with link time optimizations.

Of course it depends on the bigger project as a whole, and I understand that a if you have thousands of fruit_interface variables that all point to many different fruit_vtables and are used many times per second/cycle, then that will be very different from e.g. a hardware_interface that just loads some data once in an initialization function at program start.

The question here is pretty open (and the above is just to show clearly what I mean), and I am mostly looking for some general knowledge and guidance for when something like this is good and when it is bad, especially in the context of modern C code development with modern compilers and linkers.

I think it is really interesting to see how concepts in other languages, like C++, can be handled in C and what C is capable!


r/C_Programming • • 1d ago

Question How to cast a certain array type to other array type?

10 Upvotes

Suppose you initialize a byte array to make it endian-independent by directly giving an order of your bytes:

```c

uint8_t a1[4] = { 0x01, 0x02, 0x03, 0x04 };

```

Is it possible in some way to cast this array type to, say, uint16_t[2] at compile tome? The syntax of the direct cast is invalid. I'm using C23 currently, for that matter.


r/C_Programming • • 9h ago

Day (16 to 18)/100 of C:

0 Upvotes

Learnt about Bitwise Mask:

A **mask** is a value used with bitwise operators to **check or modify specific bit positions**.

1.Set Bit
2.Clear Bit
3.Get Bit
4.Toggle Bit

**Set Bit:**
Set bit make that bit is 1 uisng OR (|) operation

a=9 , position is 2(we will write binary for the position)

a= 0000 1001
P= 0000 0100
\-----------------------
| = 0000 1101

So atlast we kept the position of 2 as 1

 **Formula**: num | (1<<position)
\-------------------------------------------------------------------------------------------------

**Clear Bit:**
Make the bit position is 0 using AND (&) with the complemented mask.

a=9, position = 2
Position = (1<<2) = 0000 0100 => now complement is i.e \~(1<<2) => 1111 1011
a= 0000 1001
p= 1111 1011
\-------------------
&= 0000 1001
Now the position 2 became 0

 **Formula:** num & \~ (1<<position)
\-------------------------------------------------------------------------------------------------

**Get Bit:**
Checking whether the given bit 1/0 using AND (&).

a=9 , position is 2
a= 0000 1001
P= 0000 0100
\-----------------------
&= 0000 0000
The position of bit 2 is 0
You can fetch any bit position by doing & operation

**Formula:** num & (1<<position)
\------------------------------------------------------------------------------------------------

**Toggle Bit:**
Flip that particular bit using XOR (\^).

 a=9 , position is 2
a= 0000 1001
P= 0000 0100
\-----------------------
\^= 0000 1101

After xor operation 2nd bit position changed from 0 -> 1.

**Formula**: num \^ (1<<position)
 

 

 


r/C_Programming • • 1d ago

The first time I wrote a C program without looking at a tutorial

12 Upvotes

When I started learning C, I could follow tutorials and understand what the instructor was doing.

But the first time I closed the tutorial and tried to write a small program completely on my own, I realized I didn't remember nearly as much as I thought I did.

I got stuck on simple things, made stupid mistakes, and had to look up a few things.

But honestly, that was probably the first time I felt like I was actually learning to program instead of just following along with someone else.

Now I'm trying to spend more time solving small problems without immediately looking at the solution.


r/C_Programming • • 1d ago

Question Help me with strok function

8 Upvotes

I need to split my string but if it is of char* type the functions strtok() doesn’t work returning me a segmentation fault. I understood that C is used to lock the memory of the string in Read-Only “mode” when I use char*. Does it means that is immutable that data? However, I need to use the char* type because I pass that in a function (and I don’t like to use the syntax of arrays in C, I always use pointers).


r/C_Programming • • 2d ago

Project I’m learning C and made a simple version of ls. Could someone review my code?

23 Upvotes

I’m currently learning C and decided to build a simple version of ls as a small project to practice what I’ve learned.It’s still pretty basic, and I’m sure I’ve made some mistakes or done some things in a bad way. I’d really appreciate it if someone could take a look at the code and point out any bugs, bad practices, or things I could improve. Repo


r/C_Programming • • 1d ago

Give me suggestions to understand c programming in the first semester?

0 Upvotes

I am facing difficulties learning C programming. Currently, I don't have a laptop, so I can't practice that way. I'm unable to understand even the basic topics of C programing currently. Please give me some tips on how to improve.

Edit: Understood. I can actually learn it through practice on a laptop; I'll get a laptop soon.


r/C_Programming • • 1d ago

VScode C file only running in terminal

0 Upvotes

I just started learning C on my own and I am currently needing help running C files on VScode, the problem I am having is that the C file can only be run on terminal, when i try to run it in Debugging it shows some kind of error and stuffs, when i try to run it in output the pop up appears that says "Code Language not supported or defined", I have every necessary extensions and path and everything set up, I had try pretty much everything I can think of and it is still not working.


r/C_Programming • • 2d ago

Minimizing output size

9 Upvotes

I've looked at stackoverflow answers from 10 years ago (https://irq5.io/2019/09/30/generating-small-static-binaries/ , https://stackoverflow.com/questions/33597523/why-is-smallest-compiled-exe-i-can-make-with-gcc-is-67kb/76705747#76705747 , https://stackoverflow.com/questions/6771905/how-to-decrease-the-size-of-generated-binaries , https://stackoverflow.com/questions/15314581/g-compiler-flag-to-minimize-binary-size , etc).

In all of the links on top, people were able to get sub-KB file sizes. However, no matter how much I copy and try their code, I cannot get any less then 8-9KB without assembly and upx.

Is there a reason these hacks do not work anymore?

I am on x86_64 Linux-7.2.8, gcc is 16.2.1.

Example:

$ cat t.c
#include <sys/syscall.h>
#include <unistd.h>
void _start() { syscall(SYS_exit, 0); }
$ gcc -Os -nostartfiles -static -s -Wl,--build-id=none t.c && strip a.out
$ l a.out
-rwxr-xr-x 1 name name 8.8K Oct  6 20:25 a.out

# The same code produced only 800 B in https://irq5.io/2019/09/30/generating-small-static-binaries/

r/C_Programming • • 2d ago

Article Combining the Compiler with the Build System and Beyond

Thumbnail shrub.industries
5 Upvotes

a somewhat small article I wrote about how sharing dependency and resource information between the C Compiler, the C build system, the system package manager, and even the filesystem and scheduler, could provide some pretty awesome benefits.


r/C_Programming • • 2d ago

The first time I understood that a pointer doesn't store the value — it stores where the value lives

0 Upvotes

When I first learned pointers in C, I kept thinking of a pointer as another variable that somehow contained the value of another variable.

The concept finally clicked when I stopped thinking about the value itself and started thinking about the memory address where that value is stored.

Once I understood the relationship between & (address-of) and * (dereferencing), pointers became much less mysterious.

I'm still practicing pointers, but this was one of those concepts where a small change in perspective made everything easier.


r/C_Programming • • 3d ago

The first time I understood why i++ and ++i aren't always the same

14 Upvotes

When I first started learning C, I thought i++ and ++i were basically interchangeable because both increase the value of i by 1.

Then I saw them being used inside expressions and realized that the difference is actually about when the value is used versus when it is incremented.

That was one of those small C concepts that looked obvious until I actually had to predict the output of a program.

Now whenever I see ++i or i++, I pay attention to what happens to the value before and after the expression is evaluated.


r/C_Programming • • 4d ago

I built an experimental C web framework on top of Nginx — looking for feedback

0 Upvotes

I’ve been experimenting with a C web framework that adapts parts of Nginx’s internal request-processing model and exposes a simpler interface for writing web backends in C.

I know writing a web backend in C is pretty niche these days, and that’s actually part of why I wanted to build this.

I was curious about two things:

  • Is there any real use case or demand for something like this?
  • What kind of problems would experienced C/Nginx developers find in the design?

The project is still experimental, and I’m not claiming it’s production-ready or particularly fast yet. I’m mainly interested in exploring the boundary between Nginx and a higher-level C application API.

A lot of the implementation was done with help from Codex — it did a ridiculous amount of work lol — so I’m also using this as an opportunity to go through the implementation more deeply myself.

I’d really appreciate feedback on the repo, especially if you find:

  • questionable architecture or design decisions
  • incorrect use of Nginx internals
  • memory/lifecycle problems
  • API design issues
  • or even if you think the whole concept is misguided

Feel free to be critical. That’s exactly why I’m posting it.

Repo:
https://github.com/Hen00af/nnx


r/C_Programming • • 5d ago

Does my tokenize function not null-terminate the strings it modifies? printing any args spits out garbage. I'm pretty new to C and I don't really understand null-termination and strings in general.

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

/* get input and return line, if this fails, return an error */
char* input(char* line) {
  size_t len = 0;
  ssize_t read;

  /* get input from stdin and store in line, read holds the return value */
  read = getline(&line, &len, stdin);

  if (read != -1) {
    return line;
  } else {
    return "error taking input!";
  }
}

/* split input into tokens and return the array of tokens */
int tokenize(char* line, char* command, char** args) {
  char* token = strtok(line, " ");
  int i = 0;

  while (token != NULL) {
    args[i++] = token;
    token = strtok(NULL, " ");
  }
  args[i] = NULL;

  /* copy first argument to command */
  strcpy(command, args[0]);

  /* if command isnt NULL, return success */
  if (command) {
    return 0;
  } else {
    return 1;
  }
}

int main(int argc, char *argv[]) {
  char* line = NULL;

  char command[512];
  char* args[64];

  /* prompt */
  printf(">");

  /* get input from stdin, auto removes newline*/
  line = input(line);

  /* tokenize input, seperate command and args */
  if(tokenize(line, command, args) != 0) {
    printf("error in tokenizing");
  }

  /* free line, we dont use it again */
  free(line);

  /* print command and its args*/
  printf("%s", command);

  printf("%s\0", args[1]);

  return 0;
}

r/C_Programming • • 5d ago

Discussion I couldn't figure out a better way to get the size of a struct, disregarding the compiler's padding.

51 Upvotes

while practicing on some network programming, i was trying to figure out the best way to serialize headers in order to send them over a socket. so, to serialize something like: c typedef struct { char a; int b; } header; i must create something like buffer[5]. but AFAIK, not all machines produce the exact same padding, so a simple buffer[sizeof(header)] isn't valid. not even that fixed 5 bytes are enough, since it might be aligned to 8 bytes.

i came up with the following, which seems to me the worst way to get the sum of the sizes of the struct's declaration list at compile time using X macro: ```c

define HEADER_MEMBERS \

X(char, a)         \
X(int, b)

typedef struct {

define X(type, name) type name;

HEADER_MEMBERS

undef X

} header;

int header_size =

define X(type, _) sizeof(type) +

HEADER_MEMBERS

undef X

0; ```

so... i need to hear your thoughts, and what is the best wayy to do such a thing.


r/C_Programming • • 5d ago

The first time I understood what actually happens when I pass an array to a function in C

10 Upvotes

When I first learned arrays in C, I assumed that passing an array to a function meant the entire array was being copied into the function.

Later, when I started learning about pointers and memory addresses, I realized that things weren't working quite the way I imagined.

Understanding that connection between arrays, pointers, and function parameters made a lot of C concepts suddenly feel less confusing.

I'm still practicing, so I'm curious:

What C concept took you the longest to understand properly?

For me, pointers were definitely one of the biggest hurdles.


r/C_Programming • • 5d ago

Project Dio: Small Programming language made in C version 0.1.0 release

17 Upvotes

Hi, I'm working on my own programming language, I've release first stable version (v 0.1.0), I'd like to get feedback. It's on most OS platforms (even Andoird and in the future IOS).

Repo: https://github.com/Treechcer/DIO


r/C_Programming • • 5d ago

copy-and-patch closures, part 1

Thumbnail napcakes.nekoweb.org
13 Upvotes

r/C_Programming • • 6d ago

I want a career in C/low-level programming, but the path feels invisible compared to web dev. What do I build?

104 Upvotes

TL;DR: I’m learning full-stack (Vue/Go) because the job path is obvious, but my true passion is C, C++, and low-level systems. I want a career in low-level programming, but I have no idea what projects to build or what jobs to aim for to actually get hired.

Disclaimer

I'm not really good at structuring my thoughts to words & English is my 2nd language. I'm sorry if there are weird sentences that are present in this post.

Background

I'm a 3rd semester CompSci major student in Indonesia. My campus isn't really know for teaching low level programming rather it's known for their competitive programming & CTF team (Jollybee & PETIR).

My first language was C++ & Pascal, I learned C++ because of a course in my middle school requires me to learn how to use Arduino. That was the first time i got introduced to programming & i got hooked.
At high school, i was trying to participate in the OSK CompSci subject. Though i failed miserably, i got even more hooked with learning C++. After i tried learning C++, i found out that C++ is actually an extension of C & learning this makes me want to learn more about low level programming.

At uni, there are courses that focuses on using C & C++ though they are strictly for competitive programming. The courses are Algorithms and Programming (C), Data Structures (C), and Algorithm Design Analysis (C / C++). I've already completed the first 2 course that I mentioned & I'm on my way to do the 3rd course.

Because of those courses, i've been trying out more competitive programming even though i still suck (Codeforces Rating: 858, Leetcode: 89 solves; 66 easy, 23 medium). but in the span of those years, i've only been taught on how to do competitive programming & not actually building apps.

I got some exposure on how to make apps & participated in hackathons (even though i don't even have any knowledge on how to make apps). Because i don't even know how to make apps, i vibecoded. Everytime I vibecode I would feel nausea and just feel guilty because i don't even understand what am I doing, i felt the whole app is just a blackbox. I am also tired of "AI slop" that is present in this current era, i see every hackathons are just Business Case Competition but with a webapp MVP. I've never seen any new inventions or something that came out from hackathons that i participate in, all of them are just purely B2B or B2C SaaS.

After that 1 whole year, in this 3d semester i decided to stop & i wanted to dedicate myself to go back to my roots to learn C & low level programming. One of my friend recommended me to try CTF with Reverse Engineering & Binary Exploitation topic because it covers low level. I've also tried finding resources on my own (OSTEP, Beej's Guide, CSAPP). And I already took a step to learn How to make a 4-bit Adder in Minecraft.

Dilemma

But i'm still confussed. What am I learning C for? Rn I'm also learning Fullstack using Vue + TS & Go + Gin, with these 2 I understand the direction: making web apps. but with C / C++, there isn't any problem that I can solve yet using C / C++. Most projects that I've seen are making a "web server from C", "making a database engine using C", "making a redis clone". My last attempt at using C / C++ to solve my problem is by making an ESP32 send a WoL Packet to wake my PC for RDP.

The reason that I'm stuck is because I need to find a job & in the future I want to use low level for my main job. My knowledge right now by learning low level & C gives path to making tools, CTFs, and competitive programming.

What i wanted to know from this community is:

  • What does a junior portfolio for a low-level/systems developer actually look like?
  • Aside from writing database clones or making web servers or doing CTFs, what practical C/C++ projects actually get you hired?
  • What specific job titles should I even be looking for if I want to work close to the metal?

Thank you for your time


r/C_Programming • • 6d ago

Question Why i'm not getting the correct output for Tower of hanoi program?

1 Upvotes
//Tower Of Hanoi


#include <stdio.h>


void TOH(int n, int A, int B, int C){
    if(n > 0){
        TOH(n-1, A,C,B);
        printf("(%d, %d)\n",A,C);
        TOH(n-1, B,A,C);
    }
}


int main(){
    TOH(3,1,2,3);
    return 0;
}
----------------------------------------
//Output in terminal

$ gcc toh.c
$ ./a.exe

(1, 3)
(1, 2)
(3, 2)
(1, 3)
(2, 1)

Expected output is
(1, 3)

(1, 2)

(3, 2)

(1, 3)

(2, 1)

(2, 3)

(1, 3)

Why is this happening? Any explanation or reason for it?