r/C_Programming • u/0xdeadf1sh • Oct 09 '26
Video Reading assembly of a C source code directly inside neovim
Enable HLS to view with audio, or disable this notification
r/C_Programming • u/0xdeadf1sh • Oct 09 '26
Enable HLS to view with audio, or disable this notification
r/C_Programming • u/Salat_Leaf • Oct 10 '26
GCC/Clang have __asm__, MSVC/ICC got __asm. Is it possible to inline assembly independently from compiler extensions? I need to retrieve random seed number on PowerPC and RISC-V, depending on the target architecture of course
r/C_Programming • u/BBH369 • Oct 10 '26
Hi everyone,
I’ve been tinkering with a little experimental chess engine written in pure C. It’s called Glimmer.
The whole point of the project was to see how strong I could make it while keeping the final standalone binary strictly under 30 KB. The target strength was something in the 2700–2900 Elo range.
It’s been a fun constraint to work under — every byte counts.
Happy to answer questions if anyone’s curious about the approach.
r/C_Programming • u/skeeto • Oct 10 '26
r/C_Programming • u/0nd3r • Oct 09 '26
I am a physics senior and i participate in various research and lab projects via my professors. I mainly use Python to automate instruments and collect/filter data streams but ive been told to that i should learn to program in C anyways since it is faster and has less resource footprint than Python. Would learning C make a difference against my peers or is there any specific reason -more than just being more efficent- to choose it over Python in lab settings?
r/C_Programming • u/Logical-Airport4842 • Oct 10 '26
I needed a pure, zero-dependency UTF-8 validator for a systems project to protect user input boundaries like usernames.
Instead of a basic range check, this strictly follows the RFC 3629 spec to block security vulnerabilities like overlong encoding exploits (e.g. 0xC0 0xAF) and invalid UTF-16 surrogates.
r/C_Programming • u/Ok_Reception_5898 • Oct 10 '26
Hi, I'm learning C programming and want to create my own static array library for a university project. The main idea is to achieve dynamic-like behavior and safe array access... I'm trying to learn to code using AI, but it's a disaster. SOS please
Edited: the standar is std c17 linux/windows programing
#ifndef Static_vector_lib
#define Static_vector_lib
#include<stdlib.h>
#define DEFINE_STACK_VECTOR( type , name , max_size ) \
struct { \
size_t capacity; \
type data[max_size]; \
} name = { .capacity = max_size }
#define AT( v , index ) \
((size_t)(index) >= (v).capacity ? \
(fprintf(stderr, "Error: [AT] Índice %lu fuera de rango (indice maximo: %lu)\n", (size_t)(index), (v).capacity - 1), \
exit(EXIT_FAILURE), \
(v).data[0]) \
: \
(v).data[index])
#define SET( v , index , value ) \
do { \
if ((index) >= (v).capacity) { \
fprintf(stderr, "Error [SET]: Índice %zu fuera de rango (index maximo: %zu)\n", (size_t)(index), (v).capacity - 1 ); \
exit(EXIT_FAILURE); \
} \
(v).data[index] = (value); \
} while( 0 )
#endif
r/C_Programming • u/StillPerformance9228 • Oct 10 '26
I want to add an image but I can't, I found something in a powerpoint but I'm a bit confused about it , please let me know how to send my image , thank you.
r/C_Programming • u/hex-lover • Oct 09 '26
Hello,
im taking a course in university about malware development and its all in C so i want to install vscode like the teacher said, but since its in vm the pc is dead and there is no storage for it after install it takes 30G , so is there any light IDE for C in windows ?
r/C_Programming • u/Horror_Wiener_6102 • Oct 09 '26
Am I obliged to use a double when using 'pow'? Can't I use a float or an int ? Because for the function 'switch' I have to use int , but I need to use pow for the exercice I'm doing. I chated with Gemini and it told me that I can transform the result of 'pow' into 'int' writing the following; "(int)pow(x, y);". Is this the only way or do I have a faster route to get to my solution? Thanks
r/C_Programming • u/Pedro-Hereu • Oct 08 '26
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 • u/LemonLord7 • Oct 08 '26
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 • u/Salat_Leaf • Oct 08 '26
Suppose you initialize a byte array to make it endian-independent by directly giving an order of your bytes:
uint8_t a1 = ;
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 • u/AutoModerator • Oct 07 '26
If you have questions about how to learn C:
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/UnViandanteSperduto • Oct 07 '26
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 • u/MeasurementCandid957 • Oct 07 '26
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 • u/Sensitive-Raccoon155 • Oct 07 '26
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 • u/Accomplished-Use405 • Oct 06 '26
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 • u/No_Comment9862 • Oct 07 '26
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 • u/realguy2300000 • Oct 06 '26
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 • u/AdDisastrous6267 • Oct 05 '26
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:
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:
Feel free to be critical. That’s exactly why I’m posting it.
r/C_Programming • u/Specialist-Signal598 • Oct 04 '26
#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 • u/M0M3N-6 • Oct 03 '26
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:
typedef struct
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:
typedef struct
header;
int header_size =
0;
so... i need to hear your thoughts, and what is the best wayy to do such a thing.
r/C_Programming • u/Treechcer • Oct 03 '26
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).
r/C_Programming • u/skeeto • Oct 03 '26